Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1957155pxb; Fri, 25 Mar 2022 08:36:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2AXctdkqz0D7aWDJPHy1V92WOS0IAN7VyhoIfyULpyx7Ct5MUFwJPvNr9QB7wmDOWlQs6 X-Received: by 2002:a50:c099:0:b0:415:f5c7:700e with SMTP id k25-20020a50c099000000b00415f5c7700emr13674368edf.205.1648222599880; Fri, 25 Mar 2022 08:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648222599; cv=none; d=google.com; s=arc-20160816; b=t7PHHx2R2/yn8RE07n8muLunGKiTY5DQFVB8mPzLq5Xhn3aZ/pZyVSJBtvctdJ2PPt eULYr7TPznsJ4GxdgwlgnjucausKJcXlxvXMWIfWmDFhKLnLdumf7tsUw+7DDzRqodQG DjbYDUy09JMyOVyWFp6LhOwqM9F/NhONNOpj9/4EDNI1p9SLsMb8cOSGqKpoN2Q5XRfj fEEEfVij3m3hcbmHpe598F7XdD88AQLCX/ao/5c3kKScsnVIyP6Xu3KQW2OjOfxDpBuH 9M+OkzaIJPtok3C9cIwazsETHwwjZCwQG30JsJoWs5B5xBxdYUqnGsshvKqRf1mbIdh7 Ttlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-filter; bh=BjVbALIrCcHRGYopNtBlOOJvMYHiiSzq8s3qfTr81Qk=; b=kVf2eMlHGI2Q3/3UtrjEXJTEdBzjtVpIXigR9Ab2goHmgQ0bByv42POFDIRQRWcPob rtImy2m2EObY6UJ1/z7cC8stIcSjKKPgZkmjnAxOIKt6rkdoJPi28VKjklBCHGTdFPiX 06M+gsaiPPWWOSrVzoha4geZw15DCXh3wHPJ+Am+Bp0K1vOhuPoqh0+M+KJnOjY9qT3V jK2p2THpy1OoA0mlWMDb3LIZhV3QLVRkoypo4rf72IE2InZR3I/GOr8DOMFW/7rpDvVj jbHPp6waVCUKHfbkc5RXaJHVOkf4FrXE8ulOUNI3Hm4ixc/nJtDXRs7afMXGTHC3tAfi C5VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020aa7d685000000b004199e58bbf2si2607513edr.425.2022.03.25.08.36.13; Fri, 25 Mar 2022 08:36:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347383AbiCXINy (ORCPT + 99 others); Thu, 24 Mar 2022 04:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348823AbiCXINk (ORCPT ); Thu, 24 Mar 2022 04:13:40 -0400 Received: from mxout04.lancloud.ru (mxout04.lancloud.ru [45.84.86.114]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D36795D644; Thu, 24 Mar 2022 01:12:05 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout04.lancloud.ru 53F29210C5E2 Received: from LanCloud Received: from LanCloud Received: from LanCloud Subject: Re: [PATCH 07/21] ata: libahci_platform: Sanity check the DT child nodes number To: Damien Le Moal , Serge Semin , Hans de Goede , Jens Axboe CC: Serge Semin , Alexey Malahov , Pavel Parkhomenko , Rob Herring , , , References: <20220324001628.13028-1-Sergey.Semin@baikalelectronics.ru> <20220324001628.13028-8-Sergey.Semin@baikalelectronics.ru> From: Sergey Shtylyov Organization: Open Mobile Platform Message-ID: Date: Thu, 24 Mar 2022 11:12:01 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT02.lancloud.ru (fd00:f066::142) To LFEX1907.lancloud.ru (fd00:f066::207) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/24/22 4:40 AM, Damien Le Moal wrote: >> Having greater than (AHCI_MAX_PORTS = 32) ports detected isn't that >> critical from the further AHCI-platform initialization point of view since >> exceeding the ports upper limit will cause allocating more resources than >> will be used afterwards. But detecting too many child DT-nodes doesn't >> seem right since it's very unlikely to have it on an ordinary platform. In >> accordance with the AHCI specification there can't be more than 32 ports >> implemented at least due to having the CAP.NP field of 4 bits wide and the >> PI register of dword size. Thus if such situation is found the DTB must >> have been corrupted and the data read from it shouldn't be reliable. Let's >> consider that as an erroneous situation and halt further resources >> allocation. >> >> Note it's logically more correct to have the nports set only after the >> initialization value is checked for being sane. So while at it let's make >> sure nports is assigned with a correct value. >> >> Signed-off-by: Serge Semin >> --- >> drivers/ata/libahci_platform.c | 16 +++++++++++----- >> 1 file changed, 11 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c >> index 4fb9629c03ab..845042295b97 100644 >> --- a/drivers/ata/libahci_platform.c >> +++ b/drivers/ata/libahci_platform.c >> @@ -470,15 +470,21 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, >> } >> } >> >> - hpriv->nports = child_nodes = of_get_child_count(dev->of_node); >> - >> /* >> - * If no sub-node was found, we still need to set nports to >> - * one in order to be able to use the >> + * Too many sub-nodes most likely means having something wrong with >> + * firmware. If no sub-node was found, we still need to set nports >> + * to one in order to be able to use the >> * ahci_platform_[en|dis]able_[phys|regulators] functions. >> */ >> - if (!child_nodes) >> + child_nodes = of_get_child_count(dev->of_node); >> + if (child_nodes > AHCI_MAX_PORTS) { >> + rc = -EINVAL; >> + goto err_out; >> + } else if (!child_nodes) { > > No need for "else" after a return. You meant *goto*? :-) [...] MBR, Sergey