mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Wentao Liang <vulab@iscas.ac.cn>, cassel@kernel.org
Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] libata: Add error handling for pdc20621_i2c_read().
Date: Fri, 4 Apr 2025 12:55:57 +0900	[thread overview]
Message-ID: <1969f3a1-3088-49e1-a9d6-b074ff25605f@kernel.org> (raw)
In-Reply-To: <6eef4b75-2a2c-42f2-a35e-558260143dba@kernel.org>

On 4/4/25 12:54 PM, Damien Le Moal wrote:
> On 4/3/25 7:39 PM, Wentao Liang wrote:

Also forgot to mention that the patch title should be:

ata: sata_sx4: Add error handling for pdc20621_i2c_read()

And no period at the end of it please.

>> The pdc20621_prog_dimm0() calls the pdc20621_i2c_read(), but does not
> 
> The function pdc20621_prog_dimm0() calls the function pdc20621_i2c_read() but
> does...
> 
> 
>> handle the error if the read fails. This could lead to process with
>> invalid data. A proper inplementation can be found in
> 
> s/inplementation/implementation
> 
>> pdc20621_prog_dimm_global(). As mentioned in its commit:
>> bb44e154e25125bef31fa956785e90fccd24610b, the variable spd0 might be
>> used uninitialized when pdc20621_i2c_read() fails.
>>
>> Add error handling to the pdc20621_i2c_read(). If a read operation fails,
>> an error message is logged via dev_err(), and return an under-zero value
>> to represent error situlation.
> 
> and return a negative error code.
> 
>>
>> Add error handling to pdc20621_prog_dimm0() in pdc20621_dimm_init(), and
>> return a none-zero value when pdc20621_prog_dimm0() fails.
> 
> return a negative error code if pdc20621_prog_dimm0() fails.
> 
>>
>> Fixes: 4447d3515616 ("libata: convert the remaining SATA drivers to new init model")
>> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
>> ---
>>  drivers/ata/sata_sx4.c | 13 ++++++++++---
>>  1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
>> index a482741eb181..a4027eb2fb66 100644
>> --- a/drivers/ata/sata_sx4.c
>> +++ b/drivers/ata/sata_sx4.c
>> @@ -1117,9 +1117,14 @@ static int pdc20621_prog_dimm0(struct ata_host *host)
>>  	mmio += PDC_CHIP0_OFS;
>>  
>>  	for (i = 0; i < ARRAY_SIZE(pdc_i2c_read_data); i++)
>> -		pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
>> -				  pdc_i2c_read_data[i].reg,
>> -				  &spd0[pdc_i2c_read_data[i].ofs]);
>> +		if (!pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
>> +				       pdc_i2c_read_data[i].reg,
>> +				       &spd0[pdc_i2c_read_data[i].ofs])){
>> +			dev_err(host->dev,
>> +				"Failed in i2c read at index %d: device=%#x, reg=%#x\n",
>> +				i, PDC_DIMM0_SPD_DEV_ADDRESS, pdc_i2c_read_data[i].reg);
>> +			return -1;
> 
> 			return -EIO;
>> +		}
>>  
>>  	data |= (spd0[4] - 8) | ((spd0[21] != 0) << 3) | ((spd0[3]-11) << 4);
>>  	data |= ((spd0[17] / 4) << 6) | ((spd0[5] / 2) << 7) |
>> @@ -1284,6 +1289,8 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
>>  
>>  	/* Programming DIMM0 Module Control Register (index_CID0:80h) */
>>  	size = pdc20621_prog_dimm0(host);
>> +	if (size < 0)
>> +		return 1;
> 
> 		return size;
> 
>>  	dev_dbg(host->dev, "Local DIMM Size = %dMB\n", size);
>>  
>>  	/* Programming DIMM Module Global Control Register (index_CID0:88h) */
> 
> 


-- 
Damien Le Moal
Western Digital Research

      reply	other threads:[~2025-04-04  3:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03 10:39 Wentao Liang
2025-04-04  3:54 ` Damien Le Moal
2025-04-04  3:55   ` Damien Le Moal [this message]

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=1969f3a1-3088-49e1-a9d6-b074ff25605f@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vulab@iscas.ac.cn \
    /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

all inboxes | Powered by JetHome®