public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: Battery: Allow extract string from integer
@ 2007-10-29 20:29 Alexey Starikovskiy
  2007-10-29 20:57 ` Len Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Alexey Starikovskiy @ 2007-10-29 20:29 UTC (permalink / raw)
  To: LenBrown; +Cc: Linux-acpi

Some machines return integer instead of expected string.

Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
---

 drivers/acpi/battery.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 02a396d..6c06879 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -260,7 +260,7 @@ static int extract_package(struct acpi_battery *battery,
 			   union acpi_object *package,
 			   struct acpi_offsets *offsets, int num)
 {
-	int i, *x;
+	int i;
 	union acpi_object *element;
 	if (package->type != ACPI_TYPE_PACKAGE)
 		return -EFAULT;
@@ -269,16 +269,21 @@ static int extract_package(struct acpi_battery *battery,
 			return -EFAULT;
 		element = &package->package.elements[i];
 		if (offsets[i].mode) {
-			if (element->type != ACPI_TYPE_STRING &&
-			    element->type != ACPI_TYPE_BUFFER)
-				return -EFAULT;
-			strncpy((u8 *)battery + offsets[i].offset,
-				element->string.pointer, 32);
+			u8 *ptr = (u8 *)battery + offsets[i].offset;
+			if (element->type == ACPI_TYPE_STRING ||
+			    element->type == ACPI_TYPE_BUFFER)
+				strncpy(ptr, element->string.pointer, 32);
+			else if (element->type == ACPI_TYPE_INTEGER) {
+				strncpy(ptr, (u8 *)&element->integer.value,
+					sizeof(acpi_integer));
+				ptr[sizeof(acpi_integer)] = 0;
+			} else return -EFAULT;
 		} else {
-			if (element->type != ACPI_TYPE_INTEGER)
-				return -EFAULT;
-			x = (int *)((u8 *)battery + offsets[i].offset);
-			*x = element->integer.value;
+			if (element->type == ACPI_TYPE_INTEGER) {
+				int *x = (int *)((u8 *)battery +
+						offsets[i].offset);
+				*x = element->integer.value;
+			} else return -EFAULT;
 		}
 	}
 	return 0;


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

* Re: [PATCH] ACPI: Battery: Allow extract string from integer
  2007-10-29 20:29 [PATCH] ACPI: Battery: Allow extract string from integer Alexey Starikovskiy
@ 2007-10-29 20:57 ` Len Brown
  2007-10-29 22:37   ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Len Brown @ 2007-10-29 20:57 UTC (permalink / raw)
  To: Alexey Starikovskiy, Frans Pop, Andrey Borzenkov; +Cc: Linux-acpi

Applied.

Andrey, Frans,
thanks for helping with Alexey's patch this weekend.

-Len

On Monday 29 October 2007 16:29, Alexey Starikovskiy wrote:
> Some machines return integer instead of expected string.
> 
> Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
> ---
> 
>  drivers/acpi/battery.c |   25 +++++++++++++++----------
>  1 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 02a396d..6c06879 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -260,7 +260,7 @@ static int extract_package(struct acpi_battery *battery,
>  			   union acpi_object *package,
>  			   struct acpi_offsets *offsets, int num)
>  {
> -	int i, *x;
> +	int i;
>  	union acpi_object *element;
>  	if (package->type != ACPI_TYPE_PACKAGE)
>  		return -EFAULT;
> @@ -269,16 +269,21 @@ static int extract_package(struct acpi_battery *battery,
>  			return -EFAULT;
>  		element = &package->package.elements[i];
>  		if (offsets[i].mode) {
> -			if (element->type != ACPI_TYPE_STRING &&
> -			    element->type != ACPI_TYPE_BUFFER)
> -				return -EFAULT;
> -			strncpy((u8 *)battery + offsets[i].offset,
> -				element->string.pointer, 32);
> +			u8 *ptr = (u8 *)battery + offsets[i].offset;
> +			if (element->type == ACPI_TYPE_STRING ||
> +			    element->type == ACPI_TYPE_BUFFER)
> +				strncpy(ptr, element->string.pointer, 32);
> +			else if (element->type == ACPI_TYPE_INTEGER) {
> +				strncpy(ptr, (u8 *)&element->integer.value,
> +					sizeof(acpi_integer));
> +				ptr[sizeof(acpi_integer)] = 0;
> +			} else return -EFAULT;
>  		} else {
> -			if (element->type != ACPI_TYPE_INTEGER)
> -				return -EFAULT;
> -			x = (int *)((u8 *)battery + offsets[i].offset);
> -			*x = element->integer.value;
> +			if (element->type == ACPI_TYPE_INTEGER) {
> +				int *x = (int *)((u8 *)battery +
> +						offsets[i].offset);
> +				*x = element->integer.value;
> +			} else return -EFAULT;
>  		}
>  	}
>  	return 0;
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [PATCH] ACPI: Battery: Allow extract string from integer
  2007-10-29 20:57 ` Len Brown
@ 2007-10-29 22:37   ` Rafael J. Wysocki
  2007-10-30 15:12     ` Len Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2007-10-29 22:37 UTC (permalink / raw)
  To: Len Brown; +Cc: Alexey Starikovskiy, Frans Pop, Andrey Borzenkov, Linux-acpi

Hi,

On Monday, 29 October 2007 21:57, Len Brown wrote:
> Applied.
> 
> Andrey, Frans,
> thanks for helping with Alexey's patch this weekend.

Please let me know when it goes to Linus.

Thanks,
Rafael

 
> On Monday 29 October 2007 16:29, Alexey Starikovskiy wrote:
> > Some machines return integer instead of expected string.
> > 
> > Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
> > ---
> > 
> >  drivers/acpi/battery.c |   25 +++++++++++++++----------
> >  1 files changed, 15 insertions(+), 10 deletions(-)
> > 
> > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> > index 02a396d..6c06879 100644
> > --- a/drivers/acpi/battery.c
> > +++ b/drivers/acpi/battery.c
> > @@ -260,7 +260,7 @@ static int extract_package(struct acpi_battery *battery,
> >  			   union acpi_object *package,
> >  			   struct acpi_offsets *offsets, int num)
> >  {
> > -	int i, *x;
> > +	int i;
> >  	union acpi_object *element;
> >  	if (package->type != ACPI_TYPE_PACKAGE)
> >  		return -EFAULT;
> > @@ -269,16 +269,21 @@ static int extract_package(struct acpi_battery *battery,
> >  			return -EFAULT;
> >  		element = &package->package.elements[i];
> >  		if (offsets[i].mode) {
> > -			if (element->type != ACPI_TYPE_STRING &&
> > -			    element->type != ACPI_TYPE_BUFFER)
> > -				return -EFAULT;
> > -			strncpy((u8 *)battery + offsets[i].offset,
> > -				element->string.pointer, 32);
> > +			u8 *ptr = (u8 *)battery + offsets[i].offset;
> > +			if (element->type == ACPI_TYPE_STRING ||
> > +			    element->type == ACPI_TYPE_BUFFER)
> > +				strncpy(ptr, element->string.pointer, 32);
> > +			else if (element->type == ACPI_TYPE_INTEGER) {
> > +				strncpy(ptr, (u8 *)&element->integer.value,
> > +					sizeof(acpi_integer));
> > +				ptr[sizeof(acpi_integer)] = 0;
> > +			} else return -EFAULT;
> >  		} else {
> > -			if (element->type != ACPI_TYPE_INTEGER)
> > -				return -EFAULT;
> > -			x = (int *)((u8 *)battery + offsets[i].offset);
> > -			*x = element->integer.value;
> > +			if (element->type == ACPI_TYPE_INTEGER) {
> > +				int *x = (int *)((u8 *)battery +
> > +						offsets[i].offset);
> > +				*x = element->integer.value;
> > +			} else return -EFAULT;
> >  		}
> >  	}
> >  	return 0;
> > 
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> 

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

* Re: [PATCH] ACPI: Battery: Allow extract string from integer
  2007-10-29 22:37   ` Rafael J. Wysocki
@ 2007-10-30 15:12     ` Len Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Len Brown @ 2007-10-30 15:12 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Alexey Starikovskiy, Frans Pop, Andrey Borzenkov, Linux-acpi

On Monday 29 October 2007 18:37, Rafael J. Wysocki wrote:
> Hi,
> 
> On Monday, 29 October 2007 21:57, Len Brown wrote:
> > Applied.
> > 
> > Andrey, Frans,
> > thanks for helping with Alexey's patch this weekend.
> 
> Please let me know when it goes to Linus.

It went up last night, so it is included in 2.6.24-rc1-git6

thanks,
-Len

>  
> > On Monday 29 October 2007 16:29, Alexey Starikovskiy wrote:
> > > Some machines return integer instead of expected string.
> > > 
> > > Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
> > > ---
> > > 
> > >  drivers/acpi/battery.c |   25 +++++++++++++++----------
> > >  1 files changed, 15 insertions(+), 10 deletions(-)
> > > 
> > > diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> > > index 02a396d..6c06879 100644
> > > --- a/drivers/acpi/battery.c
> > > +++ b/drivers/acpi/battery.c
> > > @@ -260,7 +260,7 @@ static int extract_package(struct acpi_battery *battery,
> > >  			   union acpi_object *package,
> > >  			   struct acpi_offsets *offsets, int num)
> > >  {
> > > -	int i, *x;
> > > +	int i;
> > >  	union acpi_object *element;
> > >  	if (package->type != ACPI_TYPE_PACKAGE)
> > >  		return -EFAULT;
> > > @@ -269,16 +269,21 @@ static int extract_package(struct acpi_battery *battery,
> > >  			return -EFAULT;
> > >  		element = &package->package.elements[i];
> > >  		if (offsets[i].mode) {
> > > -			if (element->type != ACPI_TYPE_STRING &&
> > > -			    element->type != ACPI_TYPE_BUFFER)
> > > -				return -EFAULT;
> > > -			strncpy((u8 *)battery + offsets[i].offset,
> > > -				element->string.pointer, 32);
> > > +			u8 *ptr = (u8 *)battery + offsets[i].offset;
> > > +			if (element->type == ACPI_TYPE_STRING ||
> > > +			    element->type == ACPI_TYPE_BUFFER)
> > > +				strncpy(ptr, element->string.pointer, 32);
> > > +			else if (element->type == ACPI_TYPE_INTEGER) {
> > > +				strncpy(ptr, (u8 *)&element->integer.value,
> > > +					sizeof(acpi_integer));
> > > +				ptr[sizeof(acpi_integer)] = 0;
> > > +			} else return -EFAULT;
> > >  		} else {
> > > -			if (element->type != ACPI_TYPE_INTEGER)
> > > -				return -EFAULT;
> > > -			x = (int *)((u8 *)battery + offsets[i].offset);
> > > -			*x = element->integer.value;
> > > +			if (element->type == ACPI_TYPE_INTEGER) {
> > > +				int *x = (int *)((u8 *)battery +
> > > +						offsets[i].offset);
> > > +				*x = element->integer.value;
> > > +			} else return -EFAULT;
> > >  		}
> > >  	}
> > >  	return 0;
> > > 
> > > -
> > > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > 
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> > 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

end of thread, other threads:[~2007-10-30 15:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-29 20:29 [PATCH] ACPI: Battery: Allow extract string from integer Alexey Starikovskiy
2007-10-29 20:57 ` Len Brown
2007-10-29 22:37   ` Rafael J. Wysocki
2007-10-30 15:12     ` Len Brown

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