Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3499348rdg; Tue, 17 Oct 2023 17:56:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECpiCTuc5/XMuKCmAVSBQREYIWBynuktYK+eZE+WiJ38I2lHB129UaDx2Q2qFsGwK1d31Z X-Received: by 2002:a25:cbcc:0:b0:d80:1344:3cd7 with SMTP id b195-20020a25cbcc000000b00d8013443cd7mr4095138ybg.4.1697590570333; Tue, 17 Oct 2023 17:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697590570; cv=none; d=google.com; s=arc-20160816; b=QMvWLwj7KDNw/1FuqOrrv0uSH6cXgN+qe+TntuZ1C3tGyqQgWxO8oA9nAm/p9Fz+Qr gHO3kkwTMqdCwCQXiIyj6pEv9i1sIUGpDSVdnbH6Z/Jq9r9Ef52pQSYu8Xf6oe+pWZk2 RMj5Y8npYpB6Wnx3xUSiuK1hxWs+riy2Ncm35UZpVYAQwPGOHATa//2TpSEQwdZud3SV vAhN9xa67kVv0C/Csc7/OOWVKhUGhr6lyP8/aDJ7hqHHzFGsUfthAwbDrMhSX0fHiHnt w5a8rrgumJnc1ejzuSpWE0KXutDafnC9gryRtWPxpa1S9qTA6MP2fv0cd5mPvhhAxInb kP1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eBsdVbQfZnd0UbagwL4VN2FSW+PYWVlXpxtElHlS/LI=; fh=RMWyqi2YleoL2d54MUTywVJYsLVAukEwb23WvFs2EfE=; b=u4G1Y+2oW8DklZXE6JvkJB30QBqS3HFPAKJ49dOBD8w9gsNiYcZS6Z+RvdVt6WRMhE CXw4Ex4cfn/ub8LNP68rQS/NAHd5L7mXd9aSHMrxMsay7Zo6/V87C6ERV0ASdOHCMCrp +4InOMcvpkQiHz1r8G7ZoTXhUBxmnAvOy5SnW7e14rMAoAzUTMSOwJyoJLYU9lYsMgpK OsCQOf80XXpEB+Q/BPN3qmmyebp+dlpq/dLSXtrgi8mmrzOEllXHOMBJedsXyoA0bbsq 8OS2chjPONp02EAZGTsHgaSGYZHMHKqnJS13mQ1yfWSB51QN9N+gOkaYfvPay487h8N3 vVcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cR+u8GJ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id t12-20020a056a0021cc00b0069026254582si2830065pfj.98.2023.10.17.17.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 17:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cR+u8GJ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B9BF080FCC97; Tue, 17 Oct 2023 17:56:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233849AbjJRAzu (ORCPT + 99 others); Tue, 17 Oct 2023 20:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJRAzt (ORCPT ); Tue, 17 Oct 2023 20:55:49 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04B9692; Tue, 17 Oct 2023 17:55:48 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5a7dd65052aso85686407b3.0; Tue, 17 Oct 2023 17:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697590547; x=1698195347; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eBsdVbQfZnd0UbagwL4VN2FSW+PYWVlXpxtElHlS/LI=; b=cR+u8GJ+jUtI+lDTbLL5LkooRSK8VIyiCaYpwn3+0F8YNbVPKJcbDg26wKofskAr51 KT9bKbXxB3O5aBGcpZL7hoieqdKSEWWCPbA932HBZ5AIxiODkcBAXctp7dP7uH4fZ5Ar qadiNyimyaI8ToBmucMbPXX6PbR/DVufXIRMU22CEyQJb7/BFuSXJvU7iVccU4lED/ne KjB28+Hw6nURMuAoW7vy/g6BO85pI7x1EHC9L2y7YtX3fZ/UK+qNktQCa5j/EptbgJmx G3Gp4V6k5ymwu+CDmu4Sl1UFUCiUh/fKBmv3uk+kH6aXLZVmM/6EItS9VIbWxnemCPaw sWhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697590547; x=1698195347; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eBsdVbQfZnd0UbagwL4VN2FSW+PYWVlXpxtElHlS/LI=; b=HK5PlOuOFclwKTERdkN8giwuWiWDzvMZATX1HWwsISMbjDAgC+hC2Squzuu4xm9rKs Eb+XTL+n7VpuOY61MrQkV6IOVllSjPIWLZf5f01fpH5U6u9oOcDeMUzFtETazRO+7B16 BwJxaBd47vbmT/+EOLzrWLghlISq9GsoqUtCiCzm+zcLAreWtwFBEzzFPoGGqo8f5xmh YvZ7bT5GrmxsOlIfCqHNICJjyTT8Z2R5vGucoMJWoz9y3zfYtV9l7yT7cu1jmNEIPM1E wilIFDm/KM5tOqoc0ha2xANHtGNeSx6osT1nHF6OYzUC7C//lFcOMIHV5vsWqLjvv8HC RVFw== X-Gm-Message-State: AOJu0YwK+y8BrwmqWRVFul52uTfRf6MdfTG+4zrbTNk+GlMiHtXvuTjY k7Rk3ZX1H9/DgVz9dluFc7w= X-Received: by 2002:a05:690c:f96:b0:5a8:286d:339e with SMTP id df22-20020a05690c0f9600b005a8286d339emr4506682ywb.4.1697590547035; Tue, 17 Oct 2023 17:55:47 -0700 (PDT) Received: from lanran-u22.. ([169.235.25.167]) by smtp.googlemail.com with ESMTPSA id u5-20020a17090add4500b002777001ee76sm135919pjv.18.2023.10.17.17.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 17:55:45 -0700 (PDT) From: Haonan Li To: Damien Le Moal , Sergey Shtylyov , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Haonan Li Subject: Re: [PATCH] pata_lagacy: Handle failed ATA timing computation in opti82c46x_set_piomode Date: Wed, 18 Oct 2023 00:52:21 +0000 Message-Id: <20231018005220.2551586-1-lihaonan1105@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <1a0c4378-29b2-43b4-982b-0d92dfb8ed4f@kernel.org> References: <1a0c4378-29b2-43b4-982b-0d92dfb8ed4f@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 17 Oct 2023 17:56:04 -0700 (PDT) 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() and print err message. This avoids any potential use of uninitialized `tp` struct in the opti82c46x_set_piomode function. Signed-off-by: Haonan Li --- drivers/ata/pata_legacy.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c index 448a511cbc17..3c7163f97aaf 100644 --- a/drivers/ata/pata_legacy.c +++ b/drivers/ata/pata_legacy.c @@ -579,12 +579,19 @@ 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)) { + dev_err(ap->dev, "adev: unknown mode %d\n", adev->pio_mode); + 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)) { + dev_err(ap->dev, "pair: unknown mode %d\n", pair->pio_mode); + return; + } ata_timing_merge(&t, &tp, &t, ATA_TIMING_SETUP); } -- 2.34.1