On Sat, 2020-07-18 at 16:01 +0800, kernel test robot wrote: > From: kernel test robot <lkp@xxxxxxxxx> > > drivers/acpi/pci_root.c:150:37-38: WARNING: Use ARRAY_SIZE > > Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element [] > static char *get_osc_desc(u32 bit) > { > - int len = sizeof(pci_osc_control_bit) / sizeof(pci_osc_control_bit[0]); > + int len = ARRAY_SIZE(pci_osc_control_bit); > int i = 0; > > for (i = 0; i <len; i++) And likely better to not declare len at all and ARRAY_SIZE directly instead. static char *get_osc_desc(u32 bit) { int i; for (i = 0; i < ARRAY_SIZE(pci_osc_control_bit); i++) { if (bit == pci_osc_control_bit[i].bit) return pci_osc_control_bit[i].desc; } return NULL; } and also likely both arrays should be const. Something like: --- drivers/acpi/pci_root.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index f90e841c59f5..bfb437cf749a 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -122,10 +122,10 @@ static acpi_status try_get_root_bridge_busnr(acpi_handle handle, struct pci_osc_bit_struct { u32 bit; - char *desc; + const char *desc; }; -static struct pci_osc_bit_struct pci_osc_support_bit[] = { +static const struct pci_osc_bit_struct pci_osc_support_bit[] = { { OSC_PCI_EXT_CONFIG_SUPPORT, "ExtendedConfig" }, { OSC_PCI_ASPM_SUPPORT, "ASPM" }, { OSC_PCI_CLOCK_PM_SUPPORT, "ClockPM" }, @@ -135,7 +135,7 @@ static struct pci_osc_bit_struct pci_osc_support_bit[] = { { OSC_PCI_HPX_TYPE_3_SUPPORT, "HPX-Type3" }, }; -static struct pci_osc_bit_struct pci_osc_control_bit[] = { +static const struct pci_osc_bit_struct pci_osc_control_bit[] = { { OSC_PCI_EXPRESS_NATIVE_HP_CONTROL, "PCIeHotplug" }, { OSC_PCI_SHPC_NATIVE_HP_CONTROL, "SHPCHotplug" }, { OSC_PCI_EXPRESS_PME_CONTROL, "PME" }, @@ -146,17 +146,18 @@ static struct pci_osc_bit_struct pci_osc_control_bit[] = { }; static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word, - struct pci_osc_bit_struct *table, int size) + const struct pci_osc_bit_struct *table, int size) { char buf[80]; int i, len = 0; - struct pci_osc_bit_struct *entry; buf[0] = '\0'; - for (i = 0, entry = table; i < size; i++, entry++) - if (word & entry->bit) + for (i = 0; i < size; i++) { + if (word & table->bit) len += scnprintf(buf + len, sizeof(buf) - len, "%s%s", - len ? " " : "", entry->desc); + len ? " " : "", table->desc); + table++; + } dev_info(&root->device->dev, "_OSC: %s [%s]\n", msg, buf); }