Skip to contentSkip to conversation

staging: vme_user: reorder NULL check after kzalloc in fake_crcsr_init

PATCH RESEND In review Artem Lytkin 2 participants 2 messages Jul 23 – Jul 28

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

PATCH RESEND 1/1 staging: vme_user: reorder NULL check after kzalloc in fake_crcsr_init

Move the NULL check for bridge->crcsr_kernel before its use in fake_ptr_to_pci(). While fake_ptr_to_pci() is a simple cast that handles NULL safely, using a value before validating it is a bad pattern that static analyzers flag and could become a real issue if fake_ptr_to_pci() changes in the future.

---
 drivers/staging/vme_user/vme_fake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vme_user/vme_fake.c +1 -1
index 434cf760ade6c..5a4e61d204796 100644
@@ -1029,9 +1029,9 @@ static int fake_crcsr_init(struct vme_bridge *fake_bridge)
 
 	/* Allocate mem for CR/CSR image */
 	bridge->crcsr_kernel = kzalloc(VME_CRCSR_BUF_SIZE, GFP_KERNEL);
-	bridge->crcsr_bus = fake_ptr_to_pci(bridge->crcsr_kernel);
 	if (!bridge->crcsr_kernel)
 		return -ENOMEM;
+	bridge->crcsr_bus = fake_ptr_to_pci(bridge->crcsr_kernel);
 
 	vstat = fake_slot_get(fake_bridge);
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Artem Lytkin

Move the NULL check for bridge->crcsr_kernel before its use in fake_ptr_to_pci(). While fake_ptr_to_pci() is a simple cast that handles NULL safely, using a value before validating it is a bad pattern that static analyzers flag and could become a real issue if fake_ptr_to_pci() changes in the future.

Let's worry about that in the future, as this does not actually do anything at all.

Quoted 11 lines
---
 drivers/staging/vme_user/vme_fake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/vme_user/vme_fake.c +0 -0
index 434cf760ade6c..5a4e61d204796 100644

drivers/staging/vme_user/vme_fake.c static int fake_crcsr_init(struct vme_bridge *fake_bridge) · line 1032

Quoted 4 lines
drivers/staging/vme_user/vme_fake.c +0 -1
@@ -1029,9 +1029,9 @@ static int fake_crcsr_init(struct vme_bridge *fake_bridge)
 
 	/* Allocate mem for CR/CSR image */
 	bridge->crcsr_kernel = kzalloc(VME_CRCSR_BUF_SIZE, GFP_KERNEL);
-	bridge->crcsr_bus = fake_ptr_to_pci(bridge->crcsr_kernel);

Again, assigning NULL to a value is just fine.

thanks,

greg k-h