From: Joe Perches <joe@perches.com>
To: kernel test robot <lkp@intel.com>,
sathyanarayanan.kuppuswamy@linux.intel.com, bhelgaas@google.com
Cc: kbuild-all@lists.01.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, ashok.raj@intel.com
Subject: Re: [PATCH] ACPI/PCI: fix array_size.cocci warnings
Date: Sat, 18 Jul 2020 07:27:38 -0700 [thread overview]
Message-ID: <e9571e823a855f5c3c671c9c9c5ffe423b313ca4.camel@perches.com> (raw)
In-Reply-To: <20200718080145.GA55766@adfac4dc55cb>
On Sat, 2020-07-18 at 16:01 +0800, kernel test robot wrote:
> From: kernel test robot <lkp@intel.com>
>
> 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);
}
next prev parent reply other threads:[~2020-07-18 14:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-17 17:23 [PATCH v7 0/5] Simplify PCIe native ownership detection logic sathyanarayanan.kuppuswamy
2020-07-17 17:23 ` [PATCH v7 1/5] PCI: Conditionally initialize host bridge native_* members sathyanarayanan.kuppuswamy
2020-07-17 17:23 ` [PATCH v7 2/5] ACPI/PCI: Ignore _OSC negotiation result if pcie_ports_native is set sathyanarayanan.kuppuswamy
2020-07-18 8:01 ` kernel test robot
2020-07-18 8:01 ` [PATCH] ACPI/PCI: fix array_size.cocci warnings kernel test robot
2020-07-18 14:27 ` Joe Perches [this message]
2020-07-17 17:23 ` [PATCH v7 3/5] ACPI/PCI: Ignore _OSC DPC negotiation result if pcie_ports_dpc_native is set sathyanarayanan.kuppuswamy
2020-07-17 17:23 ` [PATCH v7 4/5] PCI/portdrv: Remove redundant pci_aer_available() check in DPC enable logic sathyanarayanan.kuppuswamy
2020-07-17 17:23 ` [PATCH v7 5/5] PCI/DPC: Move AER/DPC dependency checks out of DPC driver sathyanarayanan.kuppuswamy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e9571e823a855f5c3c671c9c9c5ffe423b313ca4.camel@perches.com \
--to=joe@perches.com \
--cc=ashok.raj@intel.com \
--cc=bhelgaas@google.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lkp@intel.com \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®