From: Haonan Li <lihaonan1105@gmail.com>
To: Sergey Shtylyov <s.shtylyov@omp.ru>,
Damien Le Moal <dlemoal@kernel.org>,
linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Haonan Li <lihaonan1105@gmail.com>
Subject: [PATCH] pata_lagacy: Handle failed ATA timing computation in opti82c46x_set_piomode
Date: Tue, 17 Oct 2023 23:32:34 +0000 [thread overview]
Message-ID: <20231017233234.2170437-1-lihaonan1105@gmail.com> (raw)
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@gmail.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;
+ }
/* 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;
+ }
ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP);
}
--
2.34.1
next reply other threads:[~2023-10-17 23:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 23:32 Haonan Li [this message]
2023-10-17 23:36 ` [PATCH] pata_lagacy: Handle failed ATA timing computation in opti82c46x_set_piomode Damien Le Moal
2023-10-18 0:52 ` Haonan Li
2023-10-18 6:19 ` Damien Le Moal
2023-10-18 17:15 ` Sergey Shtylyov
2023-10-18 17:59 ` Haonan Li
2023-10-18 0:50 ` kernel test robot
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=20231017233234.2170437-1-lihaonan1105@gmail.com \
--to=lihaonan1105@gmail.com \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=s.shtylyov@omp.ru \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).