Skip to contentSkip to conversation

scsi: scsi_transport_spi: fix function pointer check.

PATCH Applied [email protected] 3 participants 3 messages Jun 27, 2020 – Jun 30, 2020 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: scsi_transport_spi: fix function pointer check.

From: Tom Rix <[email protected]>

clang static analysis flags several null function pointer problems.

drivers/scsi/scsi_transport_spi.c:374:1: warning: Called function pointer is null (null dereference) [core.CallAndMessage] spi_transport_max_attr(offset, "%d\n");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reviewing the store_spi_store_max macro

	if (i->f->set_##field)
		return -EINVAL;

should be

	if (!i->f->set_##field)
		return -EINVAL;
---
 drivers/scsi/scsi_transport_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_transport_spi.c +1 -1
index f8661062ef95..f3d5b1bbd5aa 100644
@@ -339,7 +339,7 @@ store_spi_transport_##field(struct device *dev, 			\
 	struct spi_transport_attrs *tp					\
 		= (struct spi_transport_attrs *)&starget->starget_data;	\
 									\
-	if (i->f->set_##field)						\
+	if (!i->f->set_##field)						\
 		return -EINVAL;						\
 	val = simple_strtoul(buf, NULL, 0);				\
 	if (val > tp->max_##field)					\
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · On Sat, 2020-06-27 at 06:32 -0700, [email protected] wrote:

From: Tom Rix <[email protected]>

clang static analysis flags several null function pointer problems.

drivers/scsi/scsi_transport_spi.c:374:1: warning: Called function pointer is null (null dereference) [core.CallAndMessage] spi_transport_max_attr(offset, "%d\n"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reviewing the store_spi_store_max macro

	if (i->f->set_##field)
		return -EINVAL;
Quoted 6 lines

should be

	if (!i->f->set_##field)
		return -EINVAL;
Fixes 9b161a4d3e83 "[SCSI] scsi_transport_spi: convert to attribute groups")

Gosh that's an old bug ... clearly no-one is manually setting width or offset.

James

Quoted 27 lines
---
 drivers/scsi/scsi_transport_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_transport_spi.c +0 -1
index f8661062ef95..f3d5b1bbd5aa 100644
@@ -339,7 +339,7 @@ store_spi_transport_##field(struct device *dev, 	
 		\
 	struct spi_transport_attrs *tp				
 	\
 		= (struct spi_transport_attrs *)&starget-
 >starget_data;	\
 
 \
-	if (i->f->set_##field)					
	\
drivers/scsi/scsi_transport_spi.c +1 -0
+	if (!i->f->set_##field)					
	\
 		return -EINVAL;					
	\

val = simple_strtoul(buf, NULL, 0);
\
if (val > tp->max_##field)
\

#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Sat, 27 Jun 2020 06:32:42 -0700, [email protected] wrote:

clang static analysis flags several null function pointer problems.

drivers/scsi/scsi_transport_spi.c:374:1: warning: Called function pointer is null (null dereference) [core.CallAndMessage] spi_transport_max_attr(offset, "%d\n");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reviewing the store_spi_store_max macro

[...]

Applied to 5.8/scsi-fixes, thanks!

[1/1] scsi: scsi_transport_spi: Fix function pointer check

      https://git.kernel.org/mkp/scsi/c/5aee52c44d91
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering