public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] `unaligned access' in acpi get_root_bridge_busnr()
@ 2005-10-20  3:37 Peter Chubb
  2005-10-20 11:27 ` Jiri Slaby
  2005-10-20 14:44 ` [ACPI] " Alex Williamson
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Chubb @ 2005-10-20  3:37 UTC (permalink / raw)
  To: len.brown, acpi-devel, linux-kernel


In drivers/acpi/glue.c the address of an integer is cast to the
address of an unsigned long.  This breaks on systems where a long is
larger than an int --- for a start the int can be misaligned; for a
second the assignment through the pointer will overwrite part of the
next variable.

Patch is against linux-2.6.14-rc4

Signed-off-by: Peter Chubb <peterc@gelato.unsw.edu.au>

Index: linux-2.6-import/drivers/acpi/glue.c
===================================================================
--- linux-2.6-import.orig/drivers/acpi/glue.c	2005-09-09 09:08:49.928854100 +1000
+++ linux-2.6-import/drivers/acpi/glue.c	2005-10-20 13:32:32.126445742 +1000
@@ -89,46 +89,46 @@ static int acpi_find_bridge_device(struc
 /* Get PCI root bridge's handle from its segment and bus number */
 struct acpi_find_pci_root {
 	unsigned int seg;
 	unsigned int bus;
 	acpi_handle handle;
 };
 
 static acpi_status
 do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
 {
-	int *busnr = (int *)data;
+	unsigned long *busnr = (unsigned long *)data;
 	struct acpi_resource_address64 address;
 
 	if (resource->id != ACPI_RSTYPE_ADDRESS16 &&
 	    resource->id != ACPI_RSTYPE_ADDRESS32 &&
 	    resource->id != ACPI_RSTYPE_ADDRESS64)
 		return AE_OK;
 
 	acpi_resource_to_address64(resource, &address);
 	if ((address.address_length > 0) &&
 	    (address.resource_type == ACPI_BUS_NUMBER_RANGE))
 		*busnr = address.min_address_range;
 
 	return AE_OK;
 }
 
 static int get_root_bridge_busnr(acpi_handle handle)
 {
 	acpi_status status;
-	int bus, bbn;
+	unsigned long bus, bbn;
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
 	acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
 
 	status = acpi_evaluate_integer(handle, METHOD_NAME__BBN, NULL,
-				       (unsigned long *)&bbn);
+				       &bbn);
 	if (status == AE_NOT_FOUND) {
 		/* Assume bus = 0 */
 		printk(KERN_INFO PREFIX
 		       "Assume root bridge [%s] bus is 0\n",
 		       (char *)buffer.pointer);
 		status = AE_OK;
 		bbn = 0;
 	}
 	if (ACPI_FAILURE(status)) {
 		bbn = -ENODEV;
@@ -146,21 +146,21 @@ static int get_root_bridge_busnr(acpi_ha
 		goto exit;
 	/* We select _CRS */
 	if (bbn != bus) {
 		printk(KERN_INFO PREFIX
 		       "_BBN and _CRS returns different value for %s. Select _CRS\n",
 		       (char *)buffer.pointer);
 		bbn = bus;
 	}
       exit:
 	acpi_os_free(buffer.pointer);
-	return bbn;
+	return (int)bbn;
 }
 
 static acpi_status
 find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
 {
 	struct acpi_find_pci_root *find = (struct acpi_find_pci_root *)context;
 	unsigned long seg, bus;
 	acpi_status status;
 	int tmp;
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };

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

* Re: [PATCH] `unaligned access' in acpi get_root_bridge_busnr()
  2005-10-20  3:37 [PATCH] `unaligned access' in acpi get_root_bridge_busnr() Peter Chubb
@ 2005-10-20 11:27 ` Jiri Slaby
  2005-10-20 14:44 ` [ACPI] " Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2005-10-20 11:27 UTC (permalink / raw)
  To: Peter Chubb; +Cc: len.brown, acpi-devel, linux-kernel

Peter Chubb napsal(a):

>In drivers/acpi/glue.c the address of an integer is cast to the
>address of an unsigned long.  This breaks on systems where a long is
>larger than an int --- for a start the int can be misaligned; for a
>second the assignment through the pointer will overwrite part of the
>next variable.
>
>Patch is against linux-2.6.14-rc4
>
>Signed-off-by: Peter Chubb <peterc@gelato.unsw.edu.au>
>
>Index: linux-2.6-import/drivers/acpi/glue.c
>===================================================================
>--- linux-2.6-import.orig/drivers/acpi/glue.c	2005-09-09 09:08:49.928854100 +1000
>+++ linux-2.6-import/drivers/acpi/glue.c	2005-10-20 13:32:32.126445742 +1000
>@@ -89,46 +89,46 @@ static int acpi_find_bridge_device(struc
> /* Get PCI root bridge's handle from its segment and bus number */
> struct acpi_find_pci_root {
> 	unsigned int seg;
> 	unsigned int bus;
> 	acpi_handle handle;
> };
> 
> static acpi_status
> do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
> {
>-	int *busnr = (int *)data;
>+	unsigned long *busnr = (unsigned long *)data;
>  
>
Is the cast here really needed?

regards,

-- 
Jiri Slaby         www.fi.muni.cz/~xslaby
~\-/~      jirislaby@gmail.com      ~\-/~
B67499670407CE62ACC8 22A032CC55C339D47A7E


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

* Re: [ACPI] [PATCH] `unaligned access' in acpi get_root_bridge_busnr()
  2005-10-20  3:37 [PATCH] `unaligned access' in acpi get_root_bridge_busnr() Peter Chubb
  2005-10-20 11:27 ` Jiri Slaby
@ 2005-10-20 14:44 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2005-10-20 14:44 UTC (permalink / raw)
  To: Peter Chubb; +Cc: len.brown, acpi-devel, linux-kernel

On Thu, 2005-10-20 at 13:37 +1000, Peter Chubb wrote:
> In drivers/acpi/glue.c the address of an integer is cast to the
> address of an unsigned long.  This breaks on systems where a long is
> larger than an int --- for a start the int can be misaligned; for a
> second the assignment through the pointer will overwrite part of the
> next variable.
> 

   FWIW, I posted a nearly identical patch back at the end of September:

http://marc.theaimsgroup.com/?l=acpi4linux&m=112775252600038

No word of it getting anywhere.  Thanks,

	Alex

-- 


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

end of thread, other threads:[~2005-10-20 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20  3:37 [PATCH] `unaligned access' in acpi get_root_bridge_busnr() Peter Chubb
2005-10-20 11:27 ` Jiri Slaby
2005-10-20 14:44 ` [ACPI] " Alex Williamson

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