Skip to contentSkip to conversation

Use resource_size()

PATCH In review Thomas Meyer 3 participants 3 messages Aug 2, 2011 – Aug 3, 2011

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use resource_size()

Use resource_size function on resource object
instead of explicit computation.

The semantic patch that makes this output is available in scripts/coccinelle/api/resource_size.cocci.

More information about semantic patching is available at
http://coccinelle.lip6.fr/

---

drivers/media/video/davinci/vpbe_osd.c 2011-08-01 22:50:30.997700024 +0200 renamed from drivers/media/video/davinci/vpbe_osd.c 2011-07-30 11:10:29.138430171 +0200 +1 -1
diff -u -p a/drivers/media/video/davinci/vpbe_osd.c b/drivers/media/video/davinci/vpbe_osd.c
@@ -1162,7 +1162,7 @@ static int osd_probe(struct platform_dev
 		goto free_mem;
 	}
 	osd->osd_base_phys = res->start;
-	osd->osd_size = res->end - res->start + 1;
+	osd->osd_size = resource_size(res);
 	if (!request_mem_region(osd->osd_base_phys, osd->osd_size,
 				MODULE_NAME)) {
 		dev_err(osd->dev, "Unable to reserve OSD MMIO region\n");
drivers/dma/ipu/ipu_idmac.c 2011-08-01 22:52:59.680227876 +0200 renamed from drivers/dma/ipu/ipu_idmac.c 2011-07-26 00:46:07.396850877 +0200 +2 -2
diff -u -p a/drivers/dma/ipu/ipu_idmac.c b/drivers/dma/ipu/ipu_idmac.c
@@ -1707,7 +1707,7 @@ static int __init ipu_probe(struct platf
 
 	/* Remap IPU common registers */
 	ipu_data.reg_ipu = ioremap(mem_ipu->start,
-				   mem_ipu->end - mem_ipu->start + 1);
+				   resource_size(mem_ipu));
 	if (!ipu_data.reg_ipu) {
 		ret = -ENOMEM;
 		goto err_ioremap_ipu;
@@ -1715,7 +1715,7 @@ static int __init ipu_probe(struct platf
 
 	/* Remap Image Converter and Image DMA Controller registers */
 	ipu_data.reg_ic = ioremap(mem_ic->start,
-				  mem_ic->end - mem_ic->start + 1);
+				  resource_size(mem_ic));
 	if (!ipu_data.reg_ic) {
 		ret = -ENOMEM;
 		goto err_ioremap_ic;
drivers/dma/at_hdmac.c 2011-08-01 22:53:01.896882533 +0200 renamed from drivers/dma/at_hdmac.c 2011-06-07 00:56:19.895211029 +0200 +2 -2
diff -u -p a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
@@ -1216,7 +1216,7 @@ static int __init at_dma_probe(struct pl
 	atdma->dma_common.cap_mask = pdata->cap_mask;
 	atdma->all_chan_mask = (1 << pdata->nr_channels) - 1;
 
-	size = io->end - io->start + 1;
+	size = resource_size(io);
 	if (!request_mem_region(io->start, size, pdev->dev.driver->name)) {
 		err = -EBUSY;
 		goto err_kfree;
@@ -1362,7 +1362,7 @@ static int __exit at_dma_remove(struct p
 	atdma->regs = NULL;
 
 	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(io->start, io->end - io->start + 1);
+	release_mem_region(io->start, resource_size(io));
 
 	kfree(atdma);
 
drivers/xen/xen-pciback/conf_space_header.c 2011-08-01 23:02:39.180421787 +0200 renamed from drivers/xen/xen-pciback/conf_space_header.c 2011-07-26 00:46:09.730171570 +0200 +1 -1
diff -u -p a/drivers/xen/xen-pciback/conf_space_header.c b/drivers/xen/xen-pciback/conf_space_header.c
@@ -187,7 +187,7 @@ static inline void read_dev_bar(struct p
 
 	bar_info->val = res[pos].start |
 			(res[pos].flags & PCI_REGION_FLAG_MASK);
-	bar_info->len_val = res[pos].end - res[pos].start + 1;
+	bar_info->len_val = resource_size(res);
 }
 
 static void *bar_init(struct pci_dev *dev, int offset)
#1 lore raw
Quoted 8 lines · Thomas Meyer

Use resource_size function on resource object
instead of explicit computation.

The semantic patch that makes this output is available in scripts/coccinelle/api/resource_size.cocci.

More information about semantic patching is available at
http://coccinelle.lip6.fr/

You might want to split these up per driver or by subsystem and send it to the respective maintainer.

Cheers Tobias

#2 lore raw
In reply to Thomas Meyer
Quoted 9 lines · Thomas Meyer

Use resource_size function on resource object
instead of explicit computation.

The semantic patch that makes this output is available in scripts/coccinelle/api/resource_size.cocci.

More information about semantic patching is available at
http://coccinelle.lip6.fr/

[...]

drivers/xen/xen-pciback/conf_space_header.c 2011-08-01 23:02:39.180421787 +0200 static inline void read_dev_bar(struct p · line 190

Quoted 9 lines

diff -u -p a/drivers/xen/xen-pciback/conf_space_header.c b/drivers/xen/xen-pciback/conf_space_header.c

drivers/xen/xen-pciback/conf_space_header.c 2011-08-01 23:02:39.180421787 +0200 renamed from drivers/xen/xen-pciback/conf_space_header.c 2011-07-26 00:46:09.730171570 +0200 +1 -1
@@ -187,7 +187,7 @@ static inline void read_dev_bar(struct p
 
 	bar_info->val = res[pos].start |
 			(res[pos].flags & PCI_REGION_FLAG_MASK);
-	bar_info->len_val = res[pos].end - res[pos].start + 1;
+	bar_info->len_val = resource_size(res);

I didn't look at the code around this, but looking just at the patch, this seems like it should be:

bar_info->len_val = resource_size(&res[pos]);

or something like that...

Signature · 4 lines
Paulo Marques - www.grupopie.com

"As far as we know, our computer has never had an undetected error."
Weisert