Skip to contentSkip to conversation

rapidio: use resource_size()

PATCH In review Dan Carpenter 2 participants 2 messages Oct 28, 2010 – Oct 29, 2010

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

PATCH 1/1 rapidio: use resource_size()

The size calculation is done incorrectly here because it should include both the start and end (end - start + 1). It's easiest to just use resource_size() which does the right thing.

I was worried there was something non-standard going on because the printk() subtracts "end - 1", but the rest of the file uses the normal resource size calculations. This function is only called from fsl_rio_setup() in arch/powerpc/sysdev/fsl_rio.c and the calculation there is also:

	port->iores.start = law_start;
	port->iores.end = law_start + law_size - 1;

So I think this is the correct fix.

---
Compile tested only.

drivers/rapidio/rio.c +2 -2
index 68cf0c9..7b5080c 100644
@@ -1159,11 +1159,11 @@ int __devinit rio_init_mports(void)
 
 	list_for_each_entry(port, &rio_mports, node) {
 		if (!request_mem_region(port->iores.start,
-					port->iores.end - port->iores.start,
+					resource_size(&port->iores),
 					port->name)) {
 			printk(KERN_ERR
 			       "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
-			       (u64)port->iores.start, (u64)port->iores.end - 1);
+			       (u64)port->iores.start, (u64)port->iores.end);
 			rc = -ENOMEM;
 			goto out;
 		}
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dan Carpenter

The size calculation is done incorrectly here because it should include both the start and end (end - start + 1).  It's easiest to just use resource_size() which does the right thing.

I was worried there was something non-standard going on because the printk() subtracts "end - 1", but the rest of the file uses the normal resource size calculations.  This function is only called from

Looks like a non-standard hack to make the res.end equal to actual end
+ 1. I have updated the fsl_rio.c to use standard resource semantic, so the hack was long broken.

Quoted 7 lines

fsl_rio_setup() in arch/powerpc/sysdev/fsl_rio.c and the calculation there is also:
       port->iores.start = law_start;
       port->iores.end = law_start + law_size - 1;
So I think this is the correct fix.

Quoted 27 lines

---
Compile tested only.

drivers/rapidio/rio.c +1 -1
index 68cf0c9..7b5080c 100644
@@ -1159,11 +1159,11 @@ int __devinit rio_init_mports(void)
 
        list_for_each_entry(port, &rio_mports, node) {
                if (!request_mem_region(port->iores.start,
-                                       port->iores.end - port->iores.start,
+                                       resource_size(&port->iores),
                                        port->name)) {

                       printk(KERN_ERR
                              "RIO: Error requesting master port region 0x%016llx-0x%016llx\n",
-                              (u64)port->iores.start, (u64)port->iores.end - 1);
+                              (u64)port->iores.start, (u64)port->iores.end);
                       rc = -ENOMEM;
                       goto out;
               }
--
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/

Signature · 1 line
- Leo