Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3471705rdg; Tue, 17 Oct 2023 16:37:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfhDa4ML02ikYfnA2FcjMen8+/im4wv6fnZ2MfOpXMmG7mIg1XDgNCIqRL0aEJH4OKH51k X-Received: by 2002:a17:902:f550:b0:1ca:8541:e1ea with SMTP id h16-20020a170902f55000b001ca8541e1eamr4600160plf.0.1697585822042; Tue, 17 Oct 2023 16:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697585822; cv=none; d=google.com; s=arc-20160816; b=0c8+cl0EUJCA8KXInYJ7wDzR5r5CgbcrcJqNcpfsfkC+e9td5Axyk6f6Cxg7m/Wnuo ZC76qQbXC+wlRaAkUflTJl0Ko5fty++hxFvthz25/93PoKWUf+88URFnes835S+QHP9D xHFANrR7hFEn2yzW5AcCDEEW2WYIq0FyneBEWQP3oLLH2o+f8AWl/z6mn6olmKWJwmaQ CmMStk7xQUb6ODpFjACMGNyEQwGwvmClzHf+tmFJOcIz7mIYngZyILFCpTJOq3LDmzmG n6k0vb+jeIsAoPsyHak1u2l5MoDLAhymDJxaEyiCX2tI2HynVx+nw6uvqgdl1gXCSJHr 3qhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=aWhuviU611HgRXV6+lzO/Hn9XgrW7SyTv//IgChl2xo=; fh=rphZG+7tMw8I3C78+zcMQu40WbmY96+tnmgzmNOblUQ=; b=Ewhn9EMr0lgWEbUPX9nL2eJAXzOH3wS0xejrVh/5zgthIptQjqy9/56IB7NTargSXr cjTYImOuamxsMRd/P8Tmih8O8fBqUzASNs12C9leMSLpPCoztLrDIhDusF/5pwWikBEB JdlffZzsa9qaSUxVzwUDW0mT3FlUxnuHjdCK+zcoRlcJOA+tmVmFJ5XGETO1OsJL9Lr6 9gTssBCfiF1Bys4zso5AyNVDXV4ccOHV8sbQv29w2iRDbgfnwcerT3vSvLzdFx1o2Bgv G/6l7+kJCu7YRbS/JLe3bobxOMKPm5AfDXJsfxr7t6xWb0ujyJXAJmcucwHWhrzANnRJ z8yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h2kg+QHG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id x12-20020a170902ea8c00b001bb993caaedsi2729126plb.173.2023.10.17.16.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:37:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=h2kg+QHG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6620380FCBCB; Tue, 17 Oct 2023 16:36:59 -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 S1344338AbjJQXgx (ORCPT + 99 others); Tue, 17 Oct 2023 19:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234650AbjJQXgw (ORCPT ); Tue, 17 Oct 2023 19:36:52 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20D3B0; Tue, 17 Oct 2023 16:36:50 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0809C433C8; Tue, 17 Oct 2023 23:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697585810; bh=vWDxX5Zfp3qv9pYv4nE5+avCskI58/L69mzMGCW3v4g=; h=Date:Subject:To:References:From:In-Reply-To:From; b=h2kg+QHGDrbxf0pir+DJUzTxg/YtnHssBSxqcJ6qkto8Y0zFc9boBKiKC8waR/8zj JeMOaFgZ27RedCfglkjVDgDQJo9oJJaLhGYuzeTHdbaBYkzkLbxjIRhA7zvm/vfWdM tQ5k1qI4rPRvKdkw59f/yxI0Sd+EMhuLOJHeLZQsZEHtWLll5dQfzIyRNrgLqh0sR/ LEp5nlZlMSwbAnI+LBaUExp2JfBR4N5wI7GEEJRv4wWmOnrkWlf+AcPRNtuAY0Z2PP YIHp/SBX4XQuQ15dW8HTGFB7IonsiJO+Dkb3A8bLaNVChf+6i4wVtmQKYGaE1khd6p TSgZaWf1J5EWQ== Message-ID: <1a0c4378-29b2-43b4-982b-0d92dfb8ed4f@kernel.org> Date: Wed, 18 Oct 2023 08:36:48 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] pata_lagacy: Handle failed ATA timing computation in opti82c46x_set_piomode Content-Language: en-US To: Haonan Li , Sergey Shtylyov , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231017233234.2170437-1-lihaonan1105@gmail.com> From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20231017233234.2170437-1-lihaonan1105@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 16:36:59 -0700 (PDT) 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 > --- > 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