Skip to content

Commit

Permalink
PNP: ACPI: Fix string truncation warning
Browse files Browse the repository at this point in the history
LKP reports below warning when building for RISC-V.

drivers/pnp/pnpacpi/core.c:253:17:
warning: 'strncpy' specified bound 50 equals destination
size [-Wstringop-truncation]

This appears to be a valid issue since the destination string may not be
null-terminated.

To fix this, append the NUL explicitly after the strncpy().

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202307241942.Rff2Nri5-lkp@intel.com/
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Sunil V L authored and Rafael J. Wysocki committed Aug 17, 2023
1 parent 2ccdd1b commit 99c31bf
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/pnp/pnpacpi/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
else
strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));

/* Handle possible string truncation */
dev->name[sizeof(dev->name) - 1] = '\0';

if (dev->active)
pnpacpi_parse_allocated_resource(dev);

Expand Down

0 comments on commit 99c31bf

Please sign in to comment.