2013-03-25 05:38:26

by Kumar Amit Mehta

[permalink] [raw]
Subject: [PATCH] staging: vme: fix for a potential NULL pointer dereference

Audit the return value of cdev_alloc and hence fixes a potential NULL pointer
dereferencing.

Signed-off-by: Kumar Amit Mehta <[email protected]>
---
drivers/staging/vme/devices/vme_user.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index d074b1e..da7f759 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -710,6 +710,10 @@ static int vme_user_probe(struct vme_dev *vdev)

/* Register the driver as a char device */
vme_user_cdev = cdev_alloc();
+ if (!vme_user_cdev) {
+ err = -ENOMEM;
+ goto err_char;
+ }
vme_user_cdev->ops = &vme_user_fops;
vme_user_cdev->owner = THIS_MODULE;
err = cdev_add(vme_user_cdev, MKDEV(VME_MAJOR, 0), VME_DEVS);
--
1.7.9.5


2013-03-26 16:36:11

by Martyn Welch

[permalink] [raw]
Subject: Re: [PATCH] staging: vme: fix for a potential NULL pointer dereference

On 25/03/13 05:37, Kumar Amit Mehta wrote:
> Audit the return value of cdev_alloc and hence fixes a potential NULL pointer
> dereferencing.
>
> Signed-off-by: Kumar Amit Mehta <[email protected]>

Looks good to me, thanks.

Signed-off-by: Martyn Welch <[email protected]>

> ---
> drivers/staging/vme/devices/vme_user.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
> index d074b1e..da7f759 100644
> --- a/drivers/staging/vme/devices/vme_user.c
> +++ b/drivers/staging/vme/devices/vme_user.c
> @@ -710,6 +710,10 @@ static int vme_user_probe(struct vme_dev *vdev)
>
> /* Register the driver as a char device */
> vme_user_cdev = cdev_alloc();
> + if (!vme_user_cdev) {
> + err = -ENOMEM;
> + goto err_char;
> + }
> vme_user_cdev->ops = &vme_user_fops;
> vme_user_cdev->owner = THIS_MODULE;
> err = cdev_add(vme_user_cdev, MKDEV(VME_MAJOR, 0), VME_DEVS);
>


--
Martyn Welch (Lead Software Engineer) | Registered in England and Wales
GE Intelligent Platforms | (3828642) at 100 Barbirolli Square
T +44(0)1327322748 | Manchester, M2 3AB
E [email protected] | VAT:GB 927559189