lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 9 May 2020 00:31:03 +0100
From:   Colin Ian King <colin.king@...onical.com>
To:     Joe Perches <joe@...ches.com>,
        Siva Reddy Kallam <siva.kallam@...adcom.com>,
        Prashant Sreedharan <prashant@...adcom.com>,
        Michael Chan <mchan@...adcom.com>,
        "David S . Miller" <davem@...emloft.net>, netdev@...r.kernel.org
Cc:     kernel-janitors@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] net: tg3: tidy up loop, remove need to compute off with a
 multiply

On 09/05/2020 00:21, Joe Perches wrote:
> On Fri, 2020-05-08 at 23:53 +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@...onical.com>
>>
>> Currently the value for 'off' is computed using a multiplication and
>> a couple of statements later off is being incremented by len and
>> this value is never read.  Clean up the code by removing the
>> multiplication and just increment off by len on each iteration. Also
>> use len instead of TG3_OCIR_LEN.
> 
> I think this is a lot harder to read.
> 
>> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> []
>> @@ -10798,16 +10798,14 @@ static int tg3_init_hw(struct tg3 *tp, bool reset_phy)
>>  static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir)
>>  {
>>  	int i;
>> +	u32 off, len = TG3_OCIR_LEN;
>>  
>> -	for (i = 0; i < TG3_SD_NUM_RECS; i++, ocir++) {
>> -		u32 off = i * TG3_OCIR_LEN, len = TG3_OCIR_LEN;
>> -
>> +	for (i = 0, off = 0; i < TG3_SD_NUM_RECS; i++, ocir++, off += len) {
>>  		tg3_ape_scratchpad_read(tp, (u32 *) ocir, off, len);
>> -		off += len;
>>  
>>  		if (ocir->signature != TG3_OCIR_SIG_MAGIC ||
>>  		    !(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE))
>> -			memset(ocir, 0, TG3_OCIR_LEN);
>> +			memset(ocir, 0, len);
>>  	}
>>  }
> 
> My preference would be for
> 
> {
> 	int i;
> 	u32 off = 0;
> 
> 	for (i = 0; i < TG3_SD_NUM_RECS; i++) {
> 		tg3_ape_scratchpad_read(tp, (u32 *)ocir, off, TC3_OCIR_LEN);
> 
> 		if (ocir->signature != TG3_OCIR_SIG_MAGIC ||
> 		    !(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE))
> 			memset(ocir, 0, TG3_OCIR_LEN);
> 
> 		off += TG3_OCIR_LEN;
> 		ocir++;
> 	}
> 
OK, I'll send a V3 tomorrow.

Powered by blists - more mailing lists