Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Linux: Kernel

[PATCH 3/3] drivers/vlynq/vlynq.c: Fix resource size off by 1 error

 

 

Linux kernel RSS feed   Index | Next | Previous | View Threaded


julia at diku

Jul 4, 2009, 2:33 PM

Post #1 of 2 (169 views)
Permalink
[PATCH 3/3] drivers/vlynq/vlynq.c: Fix resource size off by 1 error

From: Julia Lawall <julia [at] diku>

In this case, the calls to request_mem_region, ioremap, and
release_mem_region all have a consistent length argument, len, but since in
other files (res->end - res->start) + 1, equivalent to resource_size(res),
is used for a resource-typed structure res, one could consider whether the
same should be done here.

The problem was found using the following semantic patch:
(http://www.emn.fr/x-info/coccinelle/)

// <smpl>
@@
struct resource *res;
@@

- (res->end - res->start) + 1
+ resource_size(res)

@@
struct resource *res;
@@

- res->end - res->start
+ BAD(resource_size(res))
// </smpl>

Signed-off-by: Julia Lawall <julia [at] diku>

---
drivers/vlynq/vlynq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff -u -p
a/drivers/vlynq/vlynq.c
b/drivers/vlynq/vlynq.c
--- a/drivers/vlynq/vlynq.c 2009-06-24 21:18:50.000000000 +0200
+++ b/drivers/vlynq/vlynq.c 2009-07-04 21:37:28.000000000 +0200
@@ -703,7 +703,7 @@ static int vlynq_probe(struct platform_d
dev->mem_start = mem_res->start;
dev->mem_end = mem_res->end;

- len = regs_res->end - regs_res->start;
+ len = resource_size(regs_res);
if (!request_mem_region(regs_res->start, len, dev_name(&dev->dev))) {
printk(KERN_ERR "%s: Can't request vlynq registers\n",
dev_name(&dev->dev));
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/


florian at openwrt

Jul 5, 2009, 4:23 AM

Post #2 of 2 (151 views)
Permalink
Re: [PATCH 3/3] drivers/vlynq/vlynq.c: Fix resource size off by 1 error [In reply to]

Le Saturday 04 July 2009 23:33:21 Julia Lawall, vous avez écrit :
> From: Julia Lawall <julia [at] diku>
>
> In this case, the calls to request_mem_region, ioremap, and
> release_mem_region all have a consistent length argument, len, but since in
> other files (res->end - res->start) + 1, equivalent to resource_size(res),
> is used for a resource-typed structure res, one could consider whether the
> same should be done here.

Thanks for spotting this Julia.

>
> The problem was found using the following semantic patch:
> (http://www.emn.fr/x-info/coccinelle/)
>
> // <smpl>
> @@
> struct resource *res;
> @@
>
> - (res->end - res->start) + 1
> + resource_size(res)
>
> @@
> struct resource *res;
> @@
>
> - res->end - res->start
> + BAD(resource_size(res))
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia [at] diku>

Acked-by: Florian Fainelli <florian [at] openwrt>

>
> ---
> drivers/vlynq/vlynq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff -u -p
> a/drivers/vlynq/vlynq.c
> b/drivers/vlynq/vlynq.c
> --- a/drivers/vlynq/vlynq.c 2009-06-24 21:18:50.000000000 +0200
> +++ b/drivers/vlynq/vlynq.c 2009-07-04 21:37:28.000000000 +0200
> @@ -703,7 +703,7 @@ static int vlynq_probe(struct platform_d
> dev->mem_start = mem_res->start;
> dev->mem_end = mem_res->end;
>
> - len = regs_res->end - regs_res->start;
> + len = resource_size(regs_res);
> if (!request_mem_region(regs_res->start, len, dev_name(&dev->dev))) {
> printk(KERN_ERR "%s: Can't request vlynq registers\n",
> dev_name(&dev->dev));
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo [at] vger
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/



--
Best regards, Florian Fainelli
Email : florian [at] openwrt
http://openwrt.org
-------------------------------
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo [at] vger
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Linux kernel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.