Re: [PATCH] RDMA/bnxt_re: Drop unnecessary NULL checks after container_of

From: Jason Gunthorpe
Date: Thu May 20 2021 - 11:02:52 EST


On Fri, May 14, 2021 at 08:36:06AM -0700, Guenter Roeck wrote:
> The result of container_of() operations is never NULL unless the first
> element of the embedding structure is extracted. This is either not the
> case here, or the pointer passed to container_of() is known to be not
> NULL. The NULL checks are therefore unnecessary and misleading.
> Remove them.
>
> The channges in this patch were 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@xxxxxxxxxxxx>
> ---
> drivers/infiniband/hw/bnxt_re/ib_verbs.c | 18 ------------------
> drivers/infiniband/hw/bnxt_re/main.c | 12 ------------
> 2 files changed, 30 deletions(-)

Applied to for-next, thanks

Jason