public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Deepak R Varma' <drv@mailo.com>,
	"outreachy@lists.linux.dev" <outreachy@lists.linux.dev>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-staging@lists.linux.dev" <linux-staging@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH] staging: rtl8192e: Use min_t/max_t macros for variable comparison
Date: Thu, 3 Nov 2022 08:24:15 +0000	[thread overview]
Message-ID: <d8fa86bf71694f23b8f175245722e86f@AcuMS.aculab.com> (raw)
In-Reply-To: <Y2LxC2kziM1TznhO@qemulion>

From: Deepak R Varma
> Sent: 02 November 2022 22:37
> 
> Simplify code by using min_t and max_t helper macros in place of lengthy
> if/else block oriented logical evaluation and value assignment. This
> issue is identified by coccicheck using the minmax.cocci file.
> 
> Use the *_t variants of min/max macros to avoid compiler warnings about
> data typecast.
> Also, use u32 as type for min_t macro to avoid any truncation of data
> associated with enum constant HT_AGG_SIZE_32K.
> 
> Signed-off-by: Deepak R Varma <drv@mailo.com>
> ---
>  drivers/staging/rtl8192e/rtl819x_HTProc.c | 13 ++++---------
>  1 file changed, 4 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192e/rtl819x_HTProc.c b/drivers/staging/rtl8192e/rtl819x_HTProc.c
> index 62aa8e893c34..ccb86660ab48 100644
> --- a/drivers/staging/rtl8192e/rtl819x_HTProc.c
> +++ b/drivers/staging/rtl8192e/rtl819x_HTProc.c
> @@ -587,17 +587,12 @@ void HTOnAssocRsp(struct rtllib_device *ieee)
>  			else
>  				pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
>  		} else {
> -			if (pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
> -				pHTInfo->CurrentAMPDUFactor =
> -						 pPeerHTCap->MaxRxAMPDUFactor;
> -			else
> -				pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
> +			pHTInfo->CurrentAMPDUFactor = min_t(u32, pPeerHTCap->MaxRxAMPDUFactor,
> +							    HT_AGG_SIZE_32K);

For min() to fail there must be a signed v unsigned mismatch.
Maybe that ought to be fixed.

>  		}
>  	}
> -	if (pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
> -		pHTInfo->current_mpdu_density = pHTInfo->MPDU_Density;
> -	else
> -		pHTInfo->current_mpdu_density = pPeerHTCap->MPDUDensity;
> +	pHTInfo->current_mpdu_density = max_t(u8, pHTInfo->MPDU_Density,
> +					      pPeerHTCap->MPDUDensity);

Using u8 with max_t() really doesn't make any sense.
The value will get promoted to signed int prior to the comparison.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  parent reply	other threads:[~2022-11-03  8:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 22:36 [PATCH] staging: rtl8192e: Use min_t/max_t macros for variable comparison Deepak R Varma
2022-11-02 22:56 ` Philipp Hortmann
2022-11-03  8:24 ` David Laight [this message]
2022-11-03  8:53   ` Dan Carpenter
2022-11-03  9:18     ` Deepak R Varma
2022-11-03 10:09       ` Dan Carpenter
2022-11-04  8:01         ` Deepak R Varma

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=d8fa86bf71694f23b8f175245722e86f@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=drv@mailo.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=outreachy@lists.linux.dev \
    /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