usb: gadget: Drop unnecessary NULL checks after container_of
Subsystems (2)
PATCH v2 1/1 usb: gadget: Drop unnecessary NULL checks after container_of
The parameters passed to allow_link and drop_link functions are never NULL. That means the result of container_of() on those parameters is also never NULL, even though the reference into the structure points to the first element of the structure. Remove the unnecessary NULL checks.
This change was made automatically with the following Coccinelle script. A now obsolete 'out:' label was removed manually.
@@
type t;
identifier v;
statement s;
@@
<+...
(
t v = container_of(...);
|
v = container_of(...);
)
...
when != v
- if (\( !v \| v == NULL \) ) s
...+>
---
v2: Dropped RFC, added Acked-by:, dropped now obsolete 'out:' label
drivers/usb/gadget/function/uvc_configfs.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/usb/gadget/function/uvc_configfs.c +0 -5
@@ -914,8 +914,6 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, target_fmt = container_of(to_config_group(target), struct uvcg_format, group); -if (!target_fmt) - goto out;uvcg_format_set_indices (to_config_group (target));
@@ -955,8 +953,6 @@ static void uvcg_streaming_header_drop_link(struct config_item *src,mutex_lock (&opts->lock); target_fmt = container_of(to_config_group(target), struct uvcg_format, group); -if (!target_fmt) - goto out;list_for_each_entry_safe (format_ptr, tmp, &src_hdr->formats, entry)if (format_ptr->fmt == target_fmt) {
@@ -968,7 +964,6 @@ static void uvcg_streaming_header_drop_link(struct config_item *src, --target_fmt->linked; -out:mutex_unlock (&opts->lock);mutex_unlock (su_mutex); }
Signature · 1 line
2.17.1
Hi Guenter,
Thank you for the patch.
Quoted 25 lines · Guenter Roeck
The parameters passed to
allow_linkanddrop_linkfunctions are never NULL. That means the result ofcontainer_of()on those parameters is also never NULL, even though the reference into the structure points to the first element of the structure. Remove the unnecessary NULL checks.This change was made automatically with the following Coccinelle script. A now obsolete 'out:' label was removed manually.
@@
type t;
identifier v;
statement s;
@@<+...
(
t v =container_of(...);
|
v =container_of(...);
)
...
when != v
- if (\( !v \| v == NULL \) ) s
...+>
Quoted 5 lines
Cc Laurent Pinchart <[email protected]>Cc Felipe Balbi <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Acked-by Felipe Balbi <[email protected]>Signed-off-by Guenter Roeck <[email protected]>
Quoted 36 lines
---
v2: Dropped RFC, added Acked-by:, dropped now obsolete 'out:' labeldrivers/usb/gadget/function/uvc_configfs.c | 5 ----- 1 file changed, 5 deletions(-)drivers/usb/gadget/function/uvc_configfs.c +0
-5@@ -914,8 +914,6 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, target_fmt = container_of(to_config_group(target), struct uvcg_format, group); -if (!target_fmt) - goto out;uvcg_format_set_indices (to_config_group (target));@@ -955,8 +953,6 @@ static void uvcg_streaming_header_drop_link(struct config_item *src,mutex_lock (&opts->lock); target_fmt = container_of(to_config_group(target), struct uvcg_format, group); -if (!target_fmt) - goto out;list_for_each_entry_safe (format_ptr, tmp, &src_hdr->formats, entry)if (format_ptr->fmt == target_fmt) {@@ -968,7 +964,6 @@ static void uvcg_streaming_header_drop_link(struct config_item *src, --target_fmt->linked; -out:mutex_unlock (&opts->lock);mutex_unlock (su_mutex); }
Signature · 3 lines
Regards, Laurent Pinchart