Re: [PATCH] scsi: core: Consult supported VPD page list prior to fetching page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Bart!

> On 2/14/24 10:25, Martin K. Petersen wrote:
>> +		for (unsigned int i = SCSI_VPD_HEADER_SIZE ; i < result ; i++) {
>> +			if (vpd[i] == page)
>> +				goto found;
>> +		}
>
> Can this loop be changed into a memchr() call?

Would you prefer the following?

	/* Look for page number in the returned list of supported VPDs */
	result -= SCSI_VPD_HEADER_SIZE;
	if (!memchr(&vpd[SCSI_VPD_HEADER_SIZE], page, result))
		return 0;

I find that the idiomatic for loop is easy to understand whereas the
memchr() requires a bit of squinting. But I don't really have a strong
preference. I do like that the memchr() gets rid of the goto.

>> diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
>> index cb019c80763b..6673885565e3 100644
>> --- a/include/scsi/scsi_device.h
>> +++ b/include/scsi/scsi_device.h
>> @@ -102,6 +102,7 @@ struct scsi_vpd {
>>     enum scsi_vpd_parameters {
>>   	SCSI_VPD_HEADER_SIZE = 4,
>> +	SCSI_VPD_LIST_SIZE = 36,
>>   };
>>     struct scsi_device {
>
> Since these constants are only used inside drivers/scsi/scsi.c, how about
> moving these constants into the drivers/scsi/scsi.c file?

Sure!

-- 
Martin K. Petersen	Oracle Linux Engineering




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux