public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: emaclite: Use resource_size
@ 2010-05-06  8:12 Tobias Klauser
  2010-05-06  8:23 ` David Miller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tobias Klauser @ 2010-05-06  8:12 UTC (permalink / raw)
  To: netdev, davem; +Cc: john.linn, kernel-janitors, Tobias Klauser

Use the resource_size function instead of manually calculating the
resource size.  This reduces the chance of introducing off-by-one
errors.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 drivers/net/xilinx_emaclite.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
index e9381fe..93828d5 100644
--- a/drivers/net/xilinx_emaclite.c
+++ b/drivers/net/xilinx_emaclite.c
@@ -1171,7 +1171,7 @@ static int __devinit xemaclite_of_probe(struct of_device *ofdev,
 	}
 
 	/* Get the virtual base address for the device */
-	lp->base_addr = ioremap(r_mem.start, r_mem.end - r_mem.start + 1);
+	lp->base_addr = ioremap(r_mem.start, resource_size(&r_mem));
 	if (NULL = lp->base_addr) {
 		dev_err(dev, "EmacLite: Could not allocate iomem\n");
 		rc = -EIO;
@@ -1224,7 +1224,7 @@ static int __devinit xemaclite_of_probe(struct of_device *ofdev,
 	return 0;
 
 error1:
-	release_mem_region(ndev->mem_start, r_mem.end - r_mem.start + 1);
+	release_mem_region(ndev->mem_start, resource_size(&r_mem));
 
 error2:
 	xemaclite_remove_ndev(ndev);
-- 
1.6.3.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: emaclite: Use resource_size
  2010-05-06  8:12 [PATCH] net: emaclite: Use resource_size Tobias Klauser
@ 2010-05-06  8:23 ` David Miller
  2010-05-06 10:07 ` Dan Carpenter
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2010-05-06  8:23 UTC (permalink / raw)
  To: tklauser; +Cc: netdev, john.linn, kernel-janitors

From: Tobias Klauser <tklauser@distanz.ch>
Date: Thu,  6 May 2010 10:12:20 +0200

> Use the resource_size function instead of manually calculating the
> resource size.  This reduces the chance of introducing off-by-one
> errors.
> 
> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: emaclite: Use resource_size
  2010-05-06  8:12 [PATCH] net: emaclite: Use resource_size Tobias Klauser
  2010-05-06  8:23 ` David Miller
@ 2010-05-06 10:07 ` Dan Carpenter
  2010-05-06 10:45 ` Dan Carpenter
  2010-05-06 12:06 ` Tobias Klauser
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-05-06 10:07 UTC (permalink / raw)
  To: kernel-janitors

Since you're doing this, here are some smatch warnings with potential
off-by-one bugs:

drivers/net/3c507.c +454 el16_probe1(88) warn: consider using resource_size() here
drivers/scsi/aic7xxx_old.c +8430 aic7xxx_alloc(30) warn: consider using resource_size() here
drivers/scsi/aic7xxx_old.c +9685 aic7xxx_detect(706) warn: consider using resource_size() here
drivers/scsi/aic7xxx_old.c +9698 aic7xxx_detect(719) warn: consider using resource_size() here
drivers/scsi/aic7xxx_old.c +9706 aic7xxx_detect(727) warn: consider using resource_size() here
drivers/scsi/aic7xxx_old.c +9751 aic7xxx_detect(772) warn: consider using resource_size() here
drivers/scsi/aic7xxx_old.c +10950 aic7xxx_release(14) warn: consider using resource_size() here

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: emaclite: Use resource_size
  2010-05-06  8:12 [PATCH] net: emaclite: Use resource_size Tobias Klauser
  2010-05-06  8:23 ` David Miller
  2010-05-06 10:07 ` Dan Carpenter
@ 2010-05-06 10:45 ` Dan Carpenter
  2010-05-06 12:06 ` Tobias Klauser
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2010-05-06 10:45 UTC (permalink / raw)
  To: kernel-janitors

On Thu, May 06, 2010 at 12:07:05PM +0200, Dan Carpenter wrote:
> Since you're doing this, here are some smatch warnings with potential
> off-by-one bugs:
> 

Btw.  The heuristic that smatch uses here is if the parameter is (x - y)
and neither x nor y is a sizeof() then complain.  Don't complain about
more complicated expressions like x - y - z.

If it's a simple assignment expression like:
foo = x - y;
ioremap_nocache(x, foo);
The smatch check tries to catch those as well.

Smatch checks the parameters to: ioremap_nocache(), ioremap(),
__request_region(), __release_region(), __devm_request_region(), and
__devm_release_region().

The test has a couple false positives:
drivers/net/netxen/netxen_nic_main.c +633 netxen_setup_pci_map(27) warn:
	consider using resource_size() here

Most people use x - y where both x and y are valid registers but netxen
does x - y where x is one past the end.  It does this consistently.

drivers/parport/parport_pc.c +2530 parport_pc_unregister_port(17) warn:
	consider using resource_size() here

The paraport driver frees part of the resources here and the rest a
couple lines down depending on if it's in PARPORT_MODE_ECP.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: emaclite: Use resource_size
  2010-05-06  8:12 [PATCH] net: emaclite: Use resource_size Tobias Klauser
                   ` (2 preceding siblings ...)
  2010-05-06 10:45 ` Dan Carpenter
@ 2010-05-06 12:06 ` Tobias Klauser
  3 siblings, 0 replies; 5+ messages in thread
From: Tobias Klauser @ 2010-05-06 12:06 UTC (permalink / raw)
  To: kernel-janitors

On 2010-05-06 at 12:07:05 +0200, Dan Carpenter <error27@gmail.com> wrote:
> Since you're doing this, here are some smatch warnings with potential
> off-by-one bugs:
> 
> drivers/net/3c507.c +454 el16_probe1(88) warn: consider using resource_size() here
> drivers/scsi/aic7xxx_old.c +8430 aic7xxx_alloc(30) warn: consider using resource_size() here
> drivers/scsi/aic7xxx_old.c +9685 aic7xxx_detect(706) warn: consider using resource_size() here
> drivers/scsi/aic7xxx_old.c +9698 aic7xxx_detect(719) warn: consider using resource_size() here
> drivers/scsi/aic7xxx_old.c +9706 aic7xxx_detect(727) warn: consider using resource_size() here
> drivers/scsi/aic7xxx_old.c +9751 aic7xxx_detect(772) warn: consider using resource_size() here
> drivers/scsi/aic7xxx_old.c +10950 aic7xxx_release(14) warn: consider using resource_size() here

Thanks a lot. I'll take a look at those too,

Cheers,
Tobias

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-06 12:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-06  8:12 [PATCH] net: emaclite: Use resource_size Tobias Klauser
2010-05-06  8:23 ` David Miller
2010-05-06 10:07 ` Dan Carpenter
2010-05-06 10:45 ` Dan Carpenter
2010-05-06 12:06 ` Tobias Klauser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox