driver-core: dev_to_node() should handle NULL pointers
Subsystems (2)
PATCH 1/1 driver-core: dev_to_node() should handle NULL pointers
What prompted this patch is that in dma_pool_create() we call dev_to_node() before checking whether "dev" is NULL. It looks like there are places which call dma_pool_create() with a NULL pointer. An example is in drivers/usb/gadget/amd5536udc.c.
---
Static checker fix.
include/linux/device.h +3 -1
@@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);#ifdef CONFIG_NUMA static inline int dev_to_node (struct device *dev) { -return dev->numa_node; +if (dev) +return dev->numa_node; +return -1 ; }static inline void set_dev_node (struct device *dev,int node) {
Greg Kroah-Hartman
maintainerQuoted 14 lines · Dan Carpenter
What prompted this patch is that in
dma_pool_create()we calldev_to_node()before checking whether "dev" is NULL. It looks like there are places which calldma_pool_create()with a NULL pointer. An example is indrivers/usb/gadget/amd5536udc.c.Signed-off-by Dan Carpenter <[email protected]>---
Static checker fix.include/linux/device.h +0
-0
include/linux/device.h int dev_set_name(struct device *dev, const char *name, ...); · line 719
Quoted 7 lines
include/linux/device.h +3
-1@@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);#ifdef CONFIG_NUMA static inline int dev_to_node (struct device *dev) { -return dev->numa_node; +if (dev) +return dev->numa_node; +return -1 ;
What happens if this function returns -1? Can the callers properly handle this?
thanks,
greg k-h
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Dan Carpenter
What prompted this patch is that in
dma_pool_create()we calldev_to_node()before checking whether "dev" is NULL. It looks like there are places which calldma_pool_create()with a NULL pointer. An example is indrivers/usb/gadget/amd5536udc.c.Signed-off-by Dan Carpenter <[email protected]>---
Static checker fix.
Quoted 16 lines
include/linux/device.h int dev_set_name(struct device *dev, const char *name, ...); · line 719
Quoted 12 lines
include/linux/device.h +3
-1@@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);#ifdef CONFIG_NUMA static inline int dev_to_node (struct device *dev) { -return dev->numa_node; +if (dev) +return dev->numa_node; +return -1 ;What happens if this function returns -1? Can the callers properly handle this?
Gar. Now I'm not sure any more.
-1 means no affinity and it's what the dev_to_node() returns if NUMA is disabled. But now I think probably it's important to get the NUMA node correct in dma_pool_create() so this isn't the right answer.
dma_pool_create() is not correct. It has code to handle a NULL "dev" pointer, but the dev_to_node() dereference will cause an oops before we reach it. I'm think this is a real issue that affects a couple drivers. Maybe those people compile without NUMA?
I'm not sure the right fix now.
regards,
dan carpenter
Greg Kroah-Hartman
maintainerQuoted 35 lines · Dan Carpenter
Quoted 10 lines · Greg Kroah-Hartman
Quoted 9 lines · Dan Carpenter
What prompted this patch is that in
dma_pool_create()we calldev_to_node()before checking whether "dev" is NULL. It looks like there are places which calldma_pool_create()with a NULL pointer. An example is indrivers/usb/gadget/amd5536udc.c.Signed-off-by Dan Carpenter <[email protected]>---
Static checker fix.Quoted 16 lines
include/linux/device.h int dev_set_name(struct device *dev, const char *name, ...); · line 719
Quoted 12 lines
include/linux/device.h +3
-1@@ -714,7 +714,9 @@ int dev_set_name(struct device *dev, const char *name, ...);#ifdef CONFIG_NUMA static inline int dev_to_node (struct device *dev) { -return dev->numa_node; +if (dev) +return dev->numa_node; +return -1 ;What happens if this function returns -1? Can the callers properly handle this?
Gar. Now I'm not sure any more.
-1 means no affinity and it's what the
dev_to_node()returns if NUMA is disabled. But now I think probably it's important to get the NUMA node correct indma_pool_create()so this isn't the right answer.
Quoted 6 lines
dma_pool_create()is not correct. It has code to handle a NULL "dev" pointer, but thedev_to_node()dereference will cause an oops before we reach it. I'm think this is a real issue that affects a couple drivers. Maybe those people compile without NUMA?I'm not sure the right fix now.
Ok, I'll drop this one then.
greg k-h