Skip to contentSkip to conversation

spi: amlogic-spisg: drop misleading NULL check on exdesc

PATCH In review Stepan Ionichev 3 participants 3 messages May 6 – May 7

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

PATCH 1/1 spi: amlogic-spisg: drop misleading NULL check on exdesc

aml_spisg_setup_transfer() takes a non-NULL exdesc pointer; the function dereferences exdesc unconditionally later in the body to populate the SPI scatter-gather descriptors (tx_ccsg / rx_ccsg). The sole caller, aml_spisg_transfer_one_message(), always passes a valid pointer derived from kcalloc().

The "if (exdesc)" guard around the memset() at the start of the function is therefore dead and misleading -- it suggests callers may pass NULL when in fact they may not. smatch flags the inconsistency:

drivers/spi/spi-amlogic-spisg.c:314 aml_spisg_setup_transfer()
error: we previously assumed 'exdesc' could be null (see line 261)

Drop the check; the unconditional memset matches the unconditional dereferences elsewhere in the function and removes the inconsistency that smatch reports.

No functional change.

---
 drivers/spi/spi-amlogic-spisg.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-amlogic-spisg.c +1 -2
index 19c5eba41..b2a916496 100644
@@ -258,8 +258,7 @@ static int aml_spisg_setup_transfer(struct spisg_device *spisg,
 	int ret;
 
 	memset(desc, 0, sizeof(*desc));
-	if (exdesc)
-		memset(exdesc, 0, sizeof(*exdesc));
+	memset(exdesc, 0, sizeof(*exdesc));
 	aml_spisg_set_speed(spisg, xfer->speed_hz);
 	xfer->effective_speed_hz = spisg->effective_speed_hz;
 
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Stepan,

Quoted 30 lines · Stepan Ionichev

aml_spisg_setup_transfer() takes a non-NULL exdesc pointer; the function dereferences exdesc unconditionally later in the body to populate the SPI scatter-gather descriptors (tx_ccsg / rx_ccsg). The sole caller, aml_spisg_transfer_one_message(), always passes a valid pointer derived from kcalloc().

The "if (exdesc)" guard around the memset() at the start of the function is therefore dead and misleading -- it suggests callers may pass NULL when in fact they may not. smatch flags the inconsistency:

drivers/spi/spi-amlogic-spisg.c:314 aml_spisg_setup_transfer()
error: we previously assumed 'exdesc' could be null (see line 261)

Drop the check; the unconditional memset matches the unconditional dereferences elsewhere in the function and removes the inconsistency that smatch reports.

No functional change.

---
  drivers/spi/spi-amlogic-spisg.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-amlogic-spisg.c +0 -0
index 19c5eba41..b2a916496 100644

drivers/spi/spi-amlogic-spisg.c static int aml_spisg_setup_transfer(struct spisg_device *spisg, · line 262

Quoted 7 lines
drivers/spi/spi-amlogic-spisg.c +1 -2
@@ -258,8 +258,7 @@ static int aml_spisg_setup_transfer(struct spisg_device *spisg,
         int ret;
 
         memset(desc, 0, sizeof(*desc));
-       if (exdesc)
-               memset(exdesc, 0, sizeof(*exdesc));
+       memset(exdesc, 0, sizeof(*exdesc)); >          aml_spisg_set_speed(spisg, xfer->speed_hz);
         xfer->effective_speed_hz = spisg->effective_speed_hz;
maintainer
#2 lore raw
In reply to Stepan Ionichev
Quoted 1 line · Stepan Ionichev

spi: amlogic-spisg: drop misleading NULL check on exdesc

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.2

Thanks!

[1/1] spi: amlogic-spisg: drop misleading NULL check on exdesc

      https://git.kernel.org/broonie/spi/c/54725e3049e1

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark