Skip to contentSkip to conversation

Potential NULL pointer reference in platform_device_register()

DISCUSSION Wu Zhangjin 2 participants 2 messages Dec 10, 2009

lore
Share & tools
lore
#0 lore raw

Hi, Greg KH,

Should we filter the potential NULL pointer in
platform_device_register() like this?

drivers/base/platform.c:

int platform_device_register(struct platform_device *pdev) {
+ if (!pdev)
+ return -EINVAL;

        device_initialize(&pdev->dev);
        return platform_device_add(pdev);
}

EXPORT_SYMBOL_GPL(platform_device_register);

Of course, the developers need to ensure they not register a NULL platform device, but sometimes they will not know that.

Perhaps the above method will hide the real bug, so, what about BUG_ON(! pdev).

Best Regards,
Wu Zhangjin

#1 lore raw

Review

Quoted 11 lines · Wu Zhangjin

Hi, Greg KH,

Should we filter the potential NULL pointer in
platform_device_register() like this?

drivers/base/platform.c:

int platform_device_register(struct platform_device *pdev) {

(quoted diff) +2 -0
+	 if (!pdev)
+                return -EINVAL;

Why, who is calling this function with a NULL pointer?

Quoted 8 lines
        device_initialize(&pdev->dev);
        return platform_device_add(pdev);
}

EXPORT_SYMBOL_GPL(platform_device_register);

Of course, the developers need to ensure they not register a NULL platform device, but sometimes they will not know that.

Why would you never know that?

Quoted 2 lines

Perhaps the above method will hide the real bug, so, what about BUG_ON(! pdev).

That is what happens today anyway if you pass a NULL pointer in :)

thanks,

greg k-h