Messages in this thread | | | From | Haiyang Zhang <> | Subject | RE: [PATCH] Fix null pointer error after vmbus loading | Date | Thu, 22 Oct 2009 15:39:05 +0000 |
| |
> > /* 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
| |