All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Qianfeng Rong <rongqianfeng@vivo.com>
Cc: Don Brace <don.brace@microchip.com>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	storagedev@microchip.com (open list:HEWLETT-PACKARD SMART ARRAY
	RAID DRIVER (hpsa)),
	linux-scsi@vger.kernel.org (open list:HEWLETT-PACKARD SMART
	ARRAY RAID DRIVER (hpsa)),
	linux-kernel@vger.kernel.org (open list)
Subject: Re: [PATCH 2/6] scsi: hpsa: use min()/min_t() to improve code
Date: Wed, 20 Aug 2025 13:02:37 +0100	[thread overview]
Message-ID: <20250820130237.111cc3a7@pumpkin> (raw)
In-Reply-To: <20250815121609.384914-3-rongqianfeng@vivo.com>

On Fri, 15 Aug 2025 20:16:04 +0800
Qianfeng Rong <rongqianfeng@vivo.com> wrote:

> Use min()/min_t() to reduce the code in complete_scsi_command() and
> hpsa_vpd_page_supported(), and improve readability.
> 
> Signed-off-by: Qianfeng Rong <rongqianfeng@vivo.com>
> ---
>  drivers/scsi/hpsa.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
> index c73a71ac3c29..95dfcbac997f 100644
> --- a/drivers/scsi/hpsa.c
> +++ b/drivers/scsi/hpsa.c
> @@ -2662,10 +2662,8 @@ static void complete_scsi_command(struct CommandList *cp)
>  	case CMD_TARGET_STATUS:
>  		cmd->result |= ei->ScsiStatus;
>  		/* copy the sense data */
> -		if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo))
> -			sense_data_size = SCSI_SENSE_BUFFERSIZE;
> -		else
> -			sense_data_size = sizeof(ei->SenseInfo);
> +		sense_data_size = min_t(unsigned long, SCSI_SENSE_BUFFERSIZE,
> +					sizeof(ei->SenseInfo));

Why min_t() ?
A plain min() should be fine.
If it isn't you should really need to justify why the type of one parameter
can't be changes before using min_t().

	David

>  		if (ei->SenseLen < sense_data_size)
>  			sense_data_size = ei->SenseLen;
>  		memcpy(cmd->sense_buffer, ei->SenseInfo, sense_data_size);
> @@ -3628,10 +3626,7 @@ static bool hpsa_vpd_page_supported(struct ctlr_info *h,
>  	if (rc != 0)
>  		goto exit_unsupported;
>  	pages = buf[3];
> -	if ((pages + HPSA_VPD_HEADER_SZ) <= 255)
> -		bufsize = pages + HPSA_VPD_HEADER_SZ;
> -	else
> -		bufsize = 255;
> +	bufsize = min(pages + HPSA_VPD_HEADER_SZ, 255);
>  
>  	/* Get the whole VPD page list */
>  	rc = hpsa_scsi_do_inquiry(h, scsi3addr,


  parent reply	other threads:[~2025-08-20 12:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-15 12:16 [PATCH 0/6] scsi: use min()/min_t()/max() to improve code Qianfeng Rong
2025-08-15 12:16 ` [PATCH 1/6] scsi: bfa: use min_t() " Qianfeng Rong
2025-08-20 12:13   ` David Laight
2025-08-15 12:16 ` [PATCH 2/6] scsi: hpsa: use min()/min_t() " Qianfeng Rong
2025-08-15 19:59   ` Don.Brace
2025-08-20  2:25   ` Martin K. Petersen
2025-08-20 12:02   ` David Laight [this message]
2025-08-20 12:50     ` Qianfeng Rong
2025-08-20 17:57       ` David Laight
2025-08-15 12:16 ` [PATCH 3/6] scsi: lpfc: use min() " Qianfeng Rong
2025-08-15 19:55   ` Justin Tee
2025-08-20  2:25   ` Martin K. Petersen
2025-08-15 12:16 ` [PATCH 4/6] scsi: megaraid_sas: use max() " Qianfeng Rong
2025-08-15 12:16 ` [PATCH 5/6] scsi: mpi3mr: use min() " Qianfeng Rong
2025-08-15 12:16 ` [PATCH 6/6] scsi: qla2xxx: " Qianfeng Rong
2025-08-26  2:33 ` (subset) [PATCH 0/6] scsi: use min()/min_t()/max() " Martin K. Petersen

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=20250820130237.111cc3a7@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=don.brace@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=rongqianfeng@vivo.com \
    --cc=storagedev@microchip.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.