Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: target: iscsi: Drop unnecessary container_of()

The structure pointer passed to container_of() is never NULL; that was
already checked. That means that the result of container_of() operations
on it is also never NULL, even though se_node_acl is the first element
of the structure embedding it. On top of that, it is misleading to perform
a NULL check on the result of container_of() because the position of the
contained element could change, which would make the test invalid.
Remove the unnecessary NULL check.

As it turns out, the container_of operation was only made for the purpose
of the NULL check. If the container_of is actually needed, it is repeated
later. Remove the container_of operation as well.

The NULL check was identified and removed 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
...+>

Link: https://lore.kernel.org/r/20210510040817.2050266-1-linux@roeck-us.net
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Hou Pu <houpu@bytedance.com>
Cc: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Guenter Roeck and committed by
Martin K. Petersen
998da772 8fb82abc

-7
-7
drivers/target/iscsi/iscsi_target_nego.c
··· 118 118 " CHAP auth\n"); 119 119 return -1; 120 120 } 121 - iscsi_nacl = container_of(se_nacl, struct iscsi_node_acl, 122 - se_node_acl); 123 - if (!iscsi_nacl) { 124 - pr_err("Unable to locate struct iscsi_node_acl for" 125 - " CHAP auth\n"); 126 - return -1; 127 - } 128 121 129 122 if (se_nacl->dynamic_node_acl) { 130 123 iscsi_tpg = container_of(se_nacl->se_tpg,