linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ACPI: Battery: Fix incorrect fallthrough in extract_package()
@ 2025-08-20  4:43 Kaushlendra Kumar
  2025-08-25 17:58 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Kaushlendra Kumar @ 2025-08-20  4:43 UTC (permalink / raw)
  To: rafael, lenb; +Cc: linux-acpi, Kaushlendra Kumar

Fix incorrect fallthrough behavior in the ACPI_TYPE_BUFFER case of
extract_package().

The current code processes ACPI_TYPE_BUFFER data and then falls through
to also process it as ACPI_TYPE_STRING data, which is incorrect. The
buffer case should copy the buffer data and then break, not fall through
to the string handling code. This ensures that buffer and string types
are handled correctly and independently in the switch statement.

Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
 drivers/acpi/battery.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 6905b56bf3e4..18fc5d828e70 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -445,8 +445,9 @@ static int extract_package(struct acpi_battery *battery,
 			case ACPI_TYPE_BUFFER:
 				if (len > element->buffer.length + 1)
 					len = element->buffer.length + 1;
+				strscpy(ptr, element->buffer.pointer, len);
 
-				fallthrough;
+				break;
 			case ACPI_TYPE_STRING:
 				strscpy(ptr, element->string.pointer, len);
 
-- 
2.34.1


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

* Re: [PATCH] ACPI: Battery: Fix incorrect fallthrough in extract_package()
  2025-08-20  4:43 [PATCH] ACPI: Battery: Fix incorrect fallthrough in extract_package() Kaushlendra Kumar
@ 2025-08-25 17:58 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-08-25 17:58 UTC (permalink / raw)
  To: Kaushlendra Kumar; +Cc: rafael, lenb, linux-acpi

On Wed, Aug 20, 2025 at 6:44 AM Kaushlendra Kumar
<kaushlendra.kumar@intel.com> wrote:
>
> Fix incorrect fallthrough behavior in the ACPI_TYPE_BUFFER case of
> extract_package().
>
> The current code processes ACPI_TYPE_BUFFER data and then falls through
> to also process it as ACPI_TYPE_STRING data, which is incorrect. The
> buffer case should copy the buffer data and then break, not fall through
> to the string handling code. This ensures that buffer and string types
> are handled correctly and independently in the switch statement.
>
> Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
> ---
>  drivers/acpi/battery.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 6905b56bf3e4..18fc5d828e70 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -445,8 +445,9 @@ static int extract_package(struct acpi_battery *battery,
>                         case ACPI_TYPE_BUFFER:
>                                 if (len > element->buffer.length + 1)
>                                         len = element->buffer.length + 1;
> +                               strscpy(ptr, element->buffer.pointer, len);

Why do you think that duplicating code is a good idea?

>
> -                               fallthrough;
> +                               break;
>                         case ACPI_TYPE_STRING:
>                                 strscpy(ptr, element->string.pointer, len);
>
> --

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

end of thread, other threads:[~2025-08-25 17:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-20  4:43 [PATCH] ACPI: Battery: Fix incorrect fallthrough in extract_package() Kaushlendra Kumar
2025-08-25 17:58 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).