Skip to contentSkip to conversation

driver core: faux: Move a variable assignment behind a condition check in faux_device_destroy()

PATCH In review Markus Elfring 2 participants 6 messages Jul 12 – Jul 13

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

PATCH 1/1 driver core: faux: Move a variable assignment behind a condition check in faux_device_destroy()

From: Markus Elfring <[email protected]>
Date: Sun, 12 Jul 2026 15:45:19 +0200

The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “faux_device_destroy”.

Thus avoid the risk for undefined behaviour by moving the assignment for the variable “dev” behind a condition check.

This issue was detected by using the Coccinelle software.

Fixes 35fa2d88ca9481e5caf533d58b99ca259c63b2fe ("driver core: add a faux bus for use when a simple device/bus is needed")
---
 drivers/base/faux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/faux.c +2 -1
index a8329f88222e..4eb22d082552 100644
@@ -221,11 +221,12 @@ EXPORT_SYMBOL_GPL(faux_device_create);
  */
 void faux_device_destroy(struct faux_device *faux_dev)
 {
-	struct device *dev = &faux_dev->dev;
+	struct device *dev;
 
 	if (!faux_dev)
 		return;
 
+	dev = &faux_dev->dev;
 	device_del(dev);
 
 	/* The final put_device() will clean up the memory we allocated for this device. */
Signature · 1 line
2.55.0
#1 lore raw
Quoted 9 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sun, 12 Jul 2026 15:45:19 +0200

The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “faux_device_destroy”.

Thus avoid the risk for undefined behaviour by moving the assignment for the variable “dev” behind a condition check.

There is no such "undefined behavior" here, sorry, please fix your tools.

#2 lore raw
Quoted 8 lines
Quoted 6 lines

The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “faux_device_destroy”.

Thus avoid the risk for undefined behaviour by moving the assignment for the variable “dev” behind a condition check.

There is no such "undefined behavior" here, sorry, please fix your tools.

Please take another look at related information sources.

EXP34-C: Do not dereference null pointers
https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/expressions-exp/exp34-c/

See also:
https://lore.kernel.org/kernel-janitors/[email protected]/
https://lkml.org/lkml/2026/7/2/2241

Regards,
Markus

#3 lore raw
Quoted 11 lines · Markus Elfring
Quoted 8 lines
Quoted 6 lines

The address of a data structure member was determined before a corresponding null pointer check in the implementation of the function “faux_device_destroy”.

Thus avoid the risk for undefined behaviour by moving the assignment for the variable “dev” behind a condition check.

There is no such "undefined behavior" here, sorry, please fix your tools.

Please take another look at related information sources.

Quoted 7 lines

EXP34-C: Do not dereference null pointers
https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/expressions-exp/exp34-c/

See also:
https://lore.kernel.org/kernel-janitors/[email protected]/
https://lkml.org/lkml/2026/7/2/2241

Please see the places in the past where I have rejected this very patch. Nothing has changed since then.

thanks,

greg k-h

#4 lore raw

…

Quoted 6 lines
Quoted 6 lines

Please take another look at related information sources.

EXP34-C: Do not dereference null pointers
https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/expressions-exp/exp34-c/

Quoted 6 lines
Quoted 3 lines

See also:
https://lore.kernel.org/kernel-janitors/[email protected]/
https://lkml.org/lkml/2026/7/2/2241

Please see the places in the past where I have rejected this very patch. Nothing has changed since then.

Can involved special development views be resolved better by applying scope-based resource management for the affected function implementation?

Regards,
Markus

#5 lore raw
Quoted 7 lines · Markus Elfring

…

Quoted 6 lines
Quoted 6 lines

Please take another look at related information sources.

EXP34-C: Do not dereference null pointers
https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/expressions-exp/exp34-c/

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

See also:
https://lore.kernel.org/kernel-janitors/[email protected]/
https://lkml.org/lkml/2026/7/2/2241

Please see the places in the past where I have rejected this very patch. Nothing has changed since then.

Can involved special development views be resolved better by applying scope-based resource management for the affected function implementation?

*plonk*