Re: [PATCH]s390/char/vmur.c: memory leak Fix in the driver

From: Martin Schwidefsky
Date: Mon Mar 19 2012 - 06:39:36 EST


On Mon, 19 Mar 2012 01:55:40 +0000
"Chen, Dennis (SRDC SW)" <Dennis1.Chen@xxxxxxx> wrote:

> CC'ing maintainer: Martin Schwidefsky & Heiko Carstens...
>
> -----Original Message-----
> From: Chen, Dennis (SRDC SW)
> Sent: Sunday, March 18, 2012 3:41 AM
> To: linux-kernel@xxxxxxxxxxxxxxx
> Cc: beattiem@xxxxxxxxxx; holzheu@xxxxxxxxxx; munzert@xxxxxxxxxx; linux390@xxxxxxxxxx; linux-s390@xxxxxxxxxxxxxxx; Chen, Dennis (SRDC SW)
> Subject: [PATCH]s390/char/vmur.c: memory leak Fix in the driver
>
> This patch is used to fix a memory leak issue in s390/char/vmur.c: a character device instance is
> allocated by cdev_alloc, the cdev_del will not free that space if cdev_init is applied before.
>
> Signed-off-by: dennis1.chen@xxxxxxx
> --- a/s390/char/vmur.c 2012-03-18 02:50:47.950963949 +0800
> +++ b/s390/char/vmur.c 2012-03-18 03:12:04.790936740 +0800
> @@ -903,7 +903,7 @@ static int ur_set_online(struct ccw_devi
> goto fail_urdev_put;
> }
>
> - cdev_init(urd->char_device, &ur_fops);
> + urd->char_device->ops = &ur_fops;
> urd->char_device->dev = MKDEV(major, minor);
> urd->char_device->owner = ur_fops.owner;
>

How does that fix anything? My copy of cdev_init looks like this:

void cdev_init(struct cdev *cdev, const struct file_operations *fops)
{
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
kobject_init(&cdev->kobj, &ktype_cdev_default);
cdev->ops = fops;
}

It does not allocate anything but it initializes some more fields.
The new code would only initialize the ops field. In addition
cdev_del does a kobject_put and the release function of the object
will call cdev_dynamic_release as far as I can tell. That code
should be fine as it is.

--
blue skies,
Martin.

"Reality continues to ruin my life." - Calvin.

--
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/