Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp981775iob; Fri, 13 May 2022 18:30:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6F5VsKWXTmpRXhyHLS+gHjM3TuAPtrd5GZR0YonKqFt9yLiy23D0mbe0Gt93cIMcu1fA0 X-Received: by 2002:a05:600c:4808:b0:393:fbd3:f1fa with SMTP id i8-20020a05600c480800b00393fbd3f1famr17378065wmo.100.1652491802498; Fri, 13 May 2022 18:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652491802; cv=none; d=google.com; s=arc-20160816; b=0qYsDU1AzpRCul1DZeiJYGY9Nd6Y/DKzflNZ1phc2re6zLVxmh+MtSb7S2VJs/54vL Sd5SD+wdAUcXineen7HE28c8fCQgYcGpAbPhUpmDOw/EZTAWCuPmfMrTyqoVF5CgZrNm GAnxYcyZC6lamhQczonUqfwEBk2aLtLFpXLGHIq+MYyjpPkbAa7vaQ58tZhiwOH6G4cQ enJ9H4ws3CX8xhq1Pv9I8XwiZsvGullUbmhzwR0w5Ydowj+p5u/8weooR5ei29PfTzqc 0VdCHxDXh9FBBPRmH+LK8JP+RWmChD1vlTRc7RdDYxxewYVfEXNoSUOhwQx7shApHmLr coAg== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=5/pyuexYUFM0t5yjVOWBZIC5p2ptEJasZfAOlFN5UhY=; b=LkivdQ5hAKnSl4CDshZpzekPLV/gJTaFelOcEUrauTmBmtenygPv7ZESWLtRtQ+Sjr 59XJfHJ9G8M1IPnlBtn6gzr0Vp63obcZ/riPcpQDMcnv0qwiL7zO6pr64AAgiHexF/k+ 5NN6NwDQd30sWc4PB2riKzusJIrtyOuQt4B8IrbqyIIqyfj/CpUxVlFK5Mh8fF/sCKFY KrvPC8G+8ntU495eiccvZnkEvqV7rpv8S0DoutoENXqhwNKxIDcxKJcVf5Dn8I4mkuPK eaIdVyQGb4ZNBVWAtt84DEUKwdepcV3sx3Cf02+svnzkFJWvlOV79/YRVjSBJE0TU/ni HgdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Xe8d04QY; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=g11tkIQe; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r14-20020a5d6c6e000000b0020aa33d107asi4724106wrz.1010.2022.05.13.18.30.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:30:02 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=Xe8d04QY; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=g11tkIQe; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 835CB3F663A; Fri, 13 May 2022 16:58:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350442AbiELGeO (ORCPT + 99 others); Thu, 12 May 2022 02:34:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240472AbiELGeH (ORCPT ); Thu, 12 May 2022 02:34:07 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74B2E1B4371; Wed, 11 May 2022 23:34:06 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2BD8F1F8B3; Thu, 12 May 2022 06:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1652337245; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5/pyuexYUFM0t5yjVOWBZIC5p2ptEJasZfAOlFN5UhY=; b=Xe8d04QYAgASf9HfAr+ajQeKxmjqfVqgUL/sAIBtlQyoqslDT/4dnfzfyb20Jpf5ruMHSg SHSrpt9Wmgeq0pgjiz23fEpOaye1ilZl7VJ+NlXpLJYVp2gUKzN2hMeLKQ4sOx2QQcGecY tC4tw85pG4/l9Sj138TV0zYQJcQeVjA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1652337245; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5/pyuexYUFM0t5yjVOWBZIC5p2ptEJasZfAOlFN5UhY=; b=g11tkIQe2JxDV7hUBu1nnFH5YbRkmGq9FiRWsIH2J4+jq7zIc0/V389ZwVogSlcfcH3kJ5 nigp7sz1jFXcJQCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C7C8313ABE; Thu, 12 May 2022 06:34:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yO5+L1yqfGKwUAAAMHmgww (envelope-from ); Thu, 12 May 2022 06:34:04 +0000 Message-ID: Date: Thu, 12 May 2022 08:34:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v3 09/23] ata: libahci_platform: Sanity check the DT child nodes number Content-Language: en-US To: Serge Semin , Damien Le Moal , Hans de Goede , Jens Axboe Cc: Serge Semin , Alexey Malahov , Pavel Parkhomenko , Rob Herring , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org References: <20220511231810.4928-1-Sergey.Semin@baikalelectronics.ru> <20220511231810.4928-10-Sergey.Semin@baikalelectronics.ru> From: Hannes Reinecke In-Reply-To: <20220511231810.4928-10-Sergey.Semin@baikalelectronics.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 5/12/22 01:17, Serge Semin 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 > > --- > > Changelog v2: > - Drop the else word from the child_nodes value checking if-else-if > statement (@Damien) and convert the after-else part into the ternary > operator-based statement. > --- > drivers/ata/libahci_platform.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c > index 7ff6626fd569..4e54e19f07b2 100644 > --- a/drivers/ata/libahci_platform.c > +++ b/drivers/ata/libahci_platform.c > @@ -480,15 +480,22 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev, > } > } > > - hpriv->nports = child_nodes = of_get_child_count(dev->of_node); > + /* > + * Too many sub-nodes most likely means having something wrong with > + * the firmware. > + */ > + child_nodes = of_get_child_count(dev->of_node); > + if (child_nodes > AHCI_MAX_PORTS) { > + rc = -EINVAL; > + goto err_out; > + } > > /* > * 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) > - hpriv->nports = 1; > + hpriv->nports = child_nodes ?: 1; > > hpriv->phys = devm_kcalloc(dev, hpriv->nports, sizeof(*hpriv->phys), GFP_KERNEL); > if (!hpriv->phys) { Reviewed-by: Hannes Reinecke Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), GF: Felix Imendörffer