[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1a0c4378-29b2-43b4-982b-0d92dfb8ed4f@kernel.org>
Date: Wed, 18 Oct 2023 08:36:48 +0900
From: Damien Le Moal <dlemoal@...nel.org>
To: Haonan Li <lihaonan1105@...il.com>,
Sergey Shtylyov <s.shtylyov@....ru>, linux-ide@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] pata_lagacy: Handle failed ATA timing computation in
opti82c46x_set_piomode
On 10/18/23 08:32, Haonan Li wrote:
> The function opti82c46x_set_piomode utilizes the ata_timing_compute()
> to determine the appropriate ATA timings for a given device. However,
> in certain conditions where the ata_timing_find_mode() function does
> not find a valid mode, ata_timing_compute() returns an error (-EINVAL),
> leaving the tp struct uninitialized.
>
> This patch checks the return value of ata_timing_compute().
> This avoids any potential use of uninitialized `tp` struct in the
> opti82c46x_set_piomode function.
>
> Signed-off-by: Haonan Li <lihaonan1105@...il.com>
> ---
> drivers/ata/pata_legacy.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
> index 448a511cb..d94c365cb 100644
> --- a/drivers/ata/pata_legacy.c
> +++ b/drivers/ata/pata_legacy.c
> @@ -579,12 +579,16 @@ static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
> clock = 1000000000 / khz[sysclk];
>
> /* Get the timing data in cycles */
> - ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000);
> + if (ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000)) {
> + return;
> + }
You need a message here to tell the user something is wrong. See pata_amd.c for
an example.
>
> /* Setup timing is shared */
> if (pair) {
> struct ata_timing tp;
> - ata_timing_compute(pair, pair->pio_mode, &tp, clock, 1000);
> + if (ata_timing_compute(pair, pair->pio_mode, &tp, clock, 1000)) {
> + return;
> + }
Same here. And while at it, please add a blank line after the declaration and
before your change.
>
> ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP);
> }
--
Damien Le Moal
Western Digital Research
Powered by blists - more mailing lists