If kref_get_unless_zero() fails, we should keep looking for the
next service, since the callers of this function expect that a NULL
return value means there are no more.
Signed-off-by: Marcelo Diop-Gonzalez <marcgonzalez@google.com>
Link: https://lore.kernel.org/r/20200213194001.130110-1-marcgonzalez@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
struct vchiq_service *service;
rcu_read_lock();
- service = __next_service_by_instance(state, instance, pidx);
- if (service && kref_get_unless_zero(&service->ref_count))
- service = rcu_pointer_handoff(service);
- else
- service = NULL;
+ while (1) {
+ service = __next_service_by_instance(state, instance, pidx);
+ if (!service)
+ break;
+ if (kref_get_unless_zero(&service->ref_count)) {
+ service = rcu_pointer_handoff(service);
+ break;
+ }
+ }
rcu_read_unlock();
return service;
}