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  linux-cve-announce  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]
Message-ID: <20250820130237.111cc3a7@pumpkin>
Date: Wed, 20 Aug 2025 13:02:37 +0100
From: David Laight <david.laight.linux@...il.com>
To: Qianfeng Rong <rongqianfeng@...o.com>
Cc: Don Brace <don.brace@...rochip.com>, "James E.J. Bottomley"
 <James.Bottomley@...senPartnership.com>, "Martin K. Petersen"
 <martin.petersen@...cle.com>, storagedev@...rochip.com (open
 list:HEWLETT-PACKARD SMART ARRAY RAID DRIVER (hpsa)),
 linux-scsi@...r.kernel.org (open list:HEWLETT-PACKARD SMART ARRAY RAID
 DRIVER (hpsa)), linux-kernel@...r.kernel.org (open list)
Subject: Re: [PATCH 2/6] scsi: hpsa: use min()/min_t() to improve code

On Fri, 15 Aug 2025 20:16:04 +0800
Qianfeng Rong <rongqianfeng@...o.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@...o.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,


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ