linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Ariel Elior <aelior@marvell.com>,
	Sudarsana Kalluru <skalluru@marvell.com>,
	GR-everest-linux-l2@marvell.com, Jakub Kicinski <kuba@kernel.org>,
	David Miller <davem@davemloft.net>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH 06/12] bnx2x: Search VPD with pci_vpd_find_ro_info_keyword()
Date: Tue, 24 Aug 2021 20:01:34 +0200	[thread overview]
Message-ID: <53d92923-fa8f-aa2c-ff14-340f380018b1@gmail.com> (raw)
In-Reply-To: <20210824170239.GA3477243@bjorn-Precision-5520>

On 24.08.2021 19:02, Bjorn Helgaas wrote:
> On Sun, Aug 22, 2021 at 03:54:23PM +0200, Heiner Kallweit wrote:
>> Use pci_vpd_find_ro_info_keyword() to search for keywords in VPD to
>> simplify the code.
>>
>> str_id_reg and str_id_cap hold the same string and are used in the same
>> comparison. This doesn't make sense, use one string str_id instead.
> 
> str_id_reg is printed with "%04x" (lower-case hex letters) and
> str_id_cap with "%04X" (upper-case hex letters), so the previous code
> would match either 0xabcd or 0xABCD.  After this patch, we'd match
> only the latter.
> 
Right, I missed this difference. strncasecmp() would be an easy solution.
Alternatively we could avoid this stringification and string comparison
by using kstrtouint_from_user():

kstrtouint_from_user(&vpd_data[rodi], kw_len, 16, &val)
if (val == PCI_VENDOR_ID_DELL)

But if there's no strong preference then I'd say we go the easy way.
Would you like me to re-send or are you going to adjust the patch?

> PCI_VENDOR_ID_DELL is 0x1028, so it shouldn't make any difference,
> which makes me wonder why somebody bothered with both.
> 
> But it does seem like a potential landmine to change the case
> sensitivity.  Maybe strncasecmp() instead?
> 
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>  .../net/ethernet/broadcom/bnx2x/bnx2x_main.c  | 57 +++++--------------
>>  1 file changed, 15 insertions(+), 42 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> index 0466adf8d..2c7bfc416 100644
>> --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
>> @@ -12189,11 +12189,10 @@ static int bnx2x_get_hwinfo(struct bnx2x *bp)
>>  
>>  static void bnx2x_read_fwinfo(struct bnx2x *bp)
>>  {
>> -	int i, block_end, rodi;
>> -	char str_id_reg[VENDOR_ID_LEN+1];
>> -	char str_id_cap[VENDOR_ID_LEN+1];
>> -	unsigned int vpd_len;
>> -	u8 *vpd_data, len;
>> +	char str_id[VENDOR_ID_LEN + 1];
>> +	unsigned int vpd_len, kw_len;
>> +	u8 *vpd_data;
>> +	int rodi;
>>  
>>  	memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
>>  
>> @@ -12201,46 +12200,20 @@ static void bnx2x_read_fwinfo(struct bnx2x *bp)
>>  	if (IS_ERR(vpd_data))
>>  		return;
>>  
>> -	/* VPD RO tag should be first tag after identifier string, hence
>> -	 * we should be able to find it in first BNX2X_VPD_LEN chars
>> -	 */
>> -	i = pci_vpd_find_tag(vpd_data, vpd_len, PCI_VPD_LRDT_RO_DATA);
>> -	if (i < 0)
>> -		goto out_not_found;
>> -
>> -	block_end = i + PCI_VPD_LRDT_TAG_SIZE +
>> -		    pci_vpd_lrdt_size(&vpd_data[i]);
>> -	i += PCI_VPD_LRDT_TAG_SIZE;
>> -
>> -	rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
>> -				   PCI_VPD_RO_KEYWORD_MFR_ID);
>> -	if (rodi < 0)
>> -		goto out_not_found;
>> -
>> -	len = pci_vpd_info_field_size(&vpd_data[rodi]);
>> -
>> -	if (len != VENDOR_ID_LEN)
>> +	rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len,
>> +					    PCI_VPD_RO_KEYWORD_MFR_ID, &kw_len);
>> +	if (rodi < 0 || kw_len != VENDOR_ID_LEN)
>>  		goto out_not_found;
>>  
>> -	rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
>> -
>>  	/* vendor specific info */
>> -	snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
>> -	snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
>> -	if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
>> -	    !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
>> -
>> -		rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
>> -						PCI_VPD_RO_KEYWORD_VENDOR0);
>> -		if (rodi >= 0) {
>> -			len = pci_vpd_info_field_size(&vpd_data[rodi]);
>> -
>> -			rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
>> -
>> -			if (len < 32 && (len + rodi) <= vpd_len) {
>> -				memcpy(bp->fw_ver, &vpd_data[rodi], len);
>> -				bp->fw_ver[len] = ' ';
>> -			}
>> +	snprintf(str_id, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
>> +	if (!strncmp(str_id, &vpd_data[rodi], VENDOR_ID_LEN)) {
>> +		rodi = pci_vpd_find_ro_info_keyword(vpd_data, vpd_len,
>> +						    PCI_VPD_RO_KEYWORD_VENDOR0,
>> +						    &kw_len);
>> +		if (rodi >= 0 && kw_len < sizeof(bp->fw_ver)) {
>> +			memcpy(bp->fw_ver, &vpd_data[rodi], kw_len);
>> +			bp->fw_ver[kw_len] = ' ';
>>  		}
>>  	}
>>  out_not_found:
>> -- 
>> 2.33.0
>>
>>


  reply	other threads:[~2021-08-24 18:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-22 13:46 [PATCH 00/12] PCI/VPD: Convert more users to the new VPD API functions Heiner Kallweit
2021-08-22 13:48 ` [PATCH 01/12] sfc: falcon: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 16:25   ` kernel test robot
2021-08-22 13:49 ` [PATCH 02/12] sfc: falcon: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-22 13:50 ` [PATCH 03/12] bnx2: " Heiner Kallweit
2021-08-22 13:52 ` [PATCH 04/12] bnx2: Replace open-coded version with swab32s() Heiner Kallweit
2021-08-22 13:53 ` [PATCH 05/12] bnx2x: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 17:42   ` kernel test robot
2021-08-22 13:54 ` [PATCH 06/12] bnx2x: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-24 17:02   ` Bjorn Helgaas
2021-08-24 18:01     ` Heiner Kallweit [this message]
2021-08-24 18:47       ` Bjorn Helgaas
2021-08-22 13:55 ` [PATCH 07/12] bnxt: Read VPD with pci_vpd_alloc() Heiner Kallweit
2021-08-22 18:39   ` kernel test robot
2021-08-22 13:56 ` [PATCH 08/12] bnxt: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-22 13:57 ` [PATCH 09/12] cxgb4: Validate VPD checksum with pci_vpd_check_csum() Heiner Kallweit
2021-08-22 13:58 ` [PATCH 10/12] cxgb4: Remove unused vpd_param member ec Heiner Kallweit
2021-08-22 13:59 ` [PATCH 11/12] cxgb4: Search VPD with pci_vpd_find_ro_info_keyword() Heiner Kallweit
2021-08-24 17:11   ` Bjorn Helgaas
2021-08-24 18:06     ` Heiner Kallweit
2021-08-22 14:01 ` [PATCH 12/12] scsi: cxlflash: " Heiner Kallweit
2021-08-24 18:48 ` [PATCH 00/12] PCI/VPD: Convert more users to the new VPD API functions Bjorn Helgaas

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=53d92923-fa8f-aa2c-ff14-340f380018b1@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=GR-everest-linux-l2@marvell.com \
    --cc=aelior@marvell.com \
    --cc=bhelgaas@google.com \
    --cc=davem@davemloft.net \
    --cc=helgaas@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=skalluru@marvell.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;
as well as URLs for NNTP newsgroup(s).