Linux-PM Archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: ab8500: Drop unnecessary NULL check after container_of
@ 2021-05-11 20:37 Guenter Roeck
  2021-06-03 16:52 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2021-05-11 20:37 UTC (permalink / raw
  To: Sebastian Reichel; +Cc: linux-pm, linux-kernel, 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
...+>

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/power/supply/ab8500_charger.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
index a9be10eb2c22..f407cec49aa3 100644
--- a/drivers/power/supply/ab8500_charger.c
+++ b/drivers/power/supply/ab8500_charger.c
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] power: supply: ab8500: Drop unnecessary NULL check after container_of
  2021-05-11 20:37 [PATCH] power: supply: ab8500: Drop unnecessary NULL check after container_of Guenter Roeck
@ 2021-06-03 16:52 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2021-06-03 16:52 UTC (permalink / raw
  To: Guenter Roeck; +Cc: linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1382 bytes --]

Hi,

On Tue, May 11, 2021 at 01:37:11PM -0700, Guenter Roeck wrote:
> 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
> ...+>
> 
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/ab8500_charger.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
> index a9be10eb2c22..f407cec49aa3 100644
> --- a/drivers/power/supply/ab8500_charger.c
> +++ b/drivers/power/supply/ab8500_charger.c
> @@ -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;
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-03 16:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-11 20:37 [PATCH] power: supply: ab8500: Drop unnecessary NULL check after container_of Guenter Roeck
2021-06-03 16:52 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).