2011-03-27 08:00:41

by Hillf Danton

[permalink] [raw]
Subject: [PATCH] uio: fix allocating minor id for uio device

The number of uio devices that could be used should be less than
UIO_MAX_DEVICES by design,
and this work guards any cases in which id more than UIO_MAX_DEVICES
is utilized.

Signed-off-by: Hillf Danton <[email protected]>
---

--- a/drivers/uio/uio.c 2011-01-05 08:50:20.000000000 +0800
+++ b/drivers/uio/uio.c 2011-03-27 15:05:26.000000000 +0800
@@ -381,7 +381,13 @@ static int uio_get_minor(struct uio_devi
retval = -ENOMEM;
goto exit;
}
- idev->minor = id & MAX_ID_MASK;
+ if (id < UIO_MAX_DEVICES)
+ idev->minor = id;
+ else {
+ printk(KERN_ERR "uio: too many uio devices\n");
+ retval = -EINVAL;
+ idr_remove(&uio_idr, id);
+ }
exit:
mutex_unlock(&minor_lock);
return retval;


2011-03-28 21:45:10

by Hans J. Koch

[permalink] [raw]
Subject: Re: [PATCH] uio: fix allocating minor id for uio device

On Sun, Mar 27, 2011 at 04:00:39PM +0800, Hillf Danton wrote:

(Added Greg KH to Cc:)

> The number of uio devices that could be used should be less than
> UIO_MAX_DEVICES by design,
> and this work guards any cases in which id more than UIO_MAX_DEVICES
> is utilized.
>
> Signed-off-by: Hillf Danton <[email protected]>
> ---
>
> --- a/drivers/uio/uio.c 2011-01-05 08:50:20.000000000 +0800
> +++ b/drivers/uio/uio.c 2011-03-27 15:05:26.000000000 +0800
> @@ -381,7 +381,13 @@ static int uio_get_minor(struct uio_devi
> retval = -ENOMEM;
> goto exit;
> }
> - idev->minor = id & MAX_ID_MASK;
> + if (id < UIO_MAX_DEVICES)
> + idev->minor = id;
> + else {
> + printk(KERN_ERR "uio: too many uio devices\n");

No printk(), please. Use dev_err().
Otherwise, it looks good to me.

Thanks,
Hans

> + retval = -EINVAL;
> + idr_remove(&uio_idr, id);
> + }
> exit:
> mutex_unlock(&minor_lock);
> return retval;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2011-03-29 08:41:05

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] uio: fix allocating minor id for uio device


> > - idev->minor = id & MAX_ID_MASK;
> > + if (id < UIO_MAX_DEVICES)
> > + idev->minor = id;
> > + else {

As it needs respinning anyway: If the else-block has braces, it is
recommended for the if-block, too

Regards,

Wolfram

--
Pengutronix e.K. | Wolfram Sang |
Industrial Linux Solutions | http://www.pengutronix.de/ |


Attachments:
(No filename) (388.00 B)
signature.asc (198.00 B)
Digital signature
Download all attachments

2011-03-31 12:38:52

by Hillf Danton

[permalink] [raw]
Subject: Re: [PATCH] uio: fix allocating minor id for uio device

The number of uio devices that could be used should be less than
UIO_MAX_DEVICES by design, and this work guards any cases in which id
more than UIO_MAX_DEVICES is utilized.

Signed-off-by: Hillf Danton <[email protected]>
---

--- a/drivers/uio/uio.c 2011-01-05 08:50:20.000000000 +0800
+++ b/drivers/uio/uio.c 2011-03-31 20:43:44.000000000 +0800
@@ -381,7 +381,13 @@ static int uio_get_minor(struct uio_devi
retval = -ENOMEM;
goto exit;
}
- idev->minor = id & MAX_ID_MASK;
+ if (id < UIO_MAX_DEVICES) {
+ idev->minor = id;
+ } else {
+ dev_err(idev->dev, "too many uio devices\n");
+ retval = -EINVAL;
+ idr_remove(&uio_idr, id);
+ }
exit:
mutex_unlock(&minor_lock);
return retval;

2011-03-31 17:55:18

by Hans J. Koch

[permalink] [raw]
Subject: Re: [PATCH] uio: fix allocating minor id for uio device

On Thu, Mar 31, 2011 at 08:38:47PM +0800, Hillf Danton wrote:
> The number of uio devices that could be used should be less than
> UIO_MAX_DEVICES by design, and this work guards any cases in which id
> more than UIO_MAX_DEVICES is utilized.

Looks good.

Thanks for your work,
Hans

>
> Signed-off-by: Hillf Danton <[email protected]>

Signed-off-by: Hans J. Koch <[email protected]>

> ---
>
> --- a/drivers/uio/uio.c 2011-01-05 08:50:20.000000000 +0800
> +++ b/drivers/uio/uio.c 2011-03-31 20:43:44.000000000 +0800
> @@ -381,7 +381,13 @@ static int uio_get_minor(struct uio_devi
> retval = -ENOMEM;
> goto exit;
> }
> - idev->minor = id & MAX_ID_MASK;
> + if (id < UIO_MAX_DEVICES) {
> + idev->minor = id;
> + } else {
> + dev_err(idev->dev, "too many uio devices\n");
> + retval = -EINVAL;
> + idr_remove(&uio_idr, id);
> + }
> exit:
> mutex_unlock(&minor_lock);
> return retval;
>