RE: [PATCH] Fix null pointer error after vmbus loading

From: Haiyang Zhang
Date: Thu Oct 22 2009 - 11:39:31 EST


> > /* Make sure we are not registered already */
> > - if (strlen(dev_name(&child_device_ctx->device)) != 0) {
> > + if (dev_name(&child_device_ctx->device) != NULL &&
> > + strlen(dev_name(&child_device_ctx->device)) != 0) {
>
> Why would the device name ever be NULL? Why would you need to check it
> here?

In recently kernel versions, char bus_id[BUS_ID_SIZE] in struct device has been replaced by char* type kobj.name, which is NULL if name is not yet set.
The function vmbus_child_device_create() alloc the memory for struct device_context, which includes struct device as a member. All data are initialized to zero, so the device name ptr, aka kobj.name, is NULL at the beginning:
child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL);
So, a NULL pointer checking is added to avoid null pointer dereference error if strlen() is called on the NULL name pointer. After we confirm the device isn't registered yet, we will set the name and register the device.

BTW, I forgot to switch to TXT mode in my last email, I will resend the patch in TXT only mode.

Thanks,

- Haiyang

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/