Skip to contentSkip to conversation

power: supply: ab8500: Drop unnecessary NULL check after container_of

PATCH In review Guenter Roeck 2 participants 2 messages May 11, 2021 – Jun 3, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: supply: ab8500: Drop unnecessary NULL check after container_of

The result of container_of() operations is never NULL unless the element is the first element of the embedded structure, which is not the case here. The NULL check is therefore unnecessary and misleading. Remove it.

This change was made automatically with the following Coccinelle script.

@@
type t;
identifier v;
statement s;
@@

<+...
(
t v = container_of(...);
|
v = container_of(...);
)
...
when != v
- if (\( !v \| v == NULL \) ) s
...+>

---
 drivers/power/supply/ab8500_charger.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/power/supply/ab8500_charger.c +0 -3
index a9be10eb2c22..f407cec49aa3 100644
@@ -3171,9 +3171,6 @@ static int ab8500_charger_usb_notifier_call(struct notifier_block *nb,
 	enum ab8500_usb_state bm_usb_state;
 	unsigned mA = *((unsigned *)power);
 
-	if (!di)
-		return NOTIFY_DONE;
-
 	if (event != USB_EVENT_VBUS) {
 		dev_dbg(di->dev, "not a standard host, returning\n");
 		return NOTIFY_DONE;
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 23 lines · Guenter Roeck

The result of container_of() operations is never NULL unless the element is the first element of the embedded structure, which is not the case here. The NULL check is therefore unnecessary and misleading. Remove it.

This change was made automatically with the following Coccinelle script.

@@
type t;
identifier v;
statement s;
@@

<+...
(
t v = container_of(...);
|
v = container_of(...);
)
...
when != v
- if (\( !v \| v == NULL \) ) s
...+>

Quoted 2 lines

---

Thanks, queued.

-- Sebastian

Quoted 20 lines
 drivers/power/supply/ab8500_charger.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/power/supply/ab8500_charger.c +0 -3
index a9be10eb2c22..f407cec49aa3 100644
@@ -3171,9 +3171,6 @@ static int ab8500_charger_usb_notifier_call(struct notifier_block *nb,
 	enum ab8500_usb_state bm_usb_state;
 	unsigned mA = *((unsigned *)power);
 
-	if (!di)
-		return NOTIFY_DONE;
-
 	if (event != USB_EVENT_VBUS) {
 		dev_dbg(di->dev, "not a standard host, returning\n");
 		return NOTIFY_DONE;
Signature · 1 line
2.25.1