Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6822347yba; Wed, 1 May 2019 21:55:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCVO962pZ1xrQ0G89reegvbAEml3Jfmlm0y5Ib9pFHlTlT7O1SOKX0zYkL7q0sPjQ0QTvr X-Received: by 2002:a65:4144:: with SMTP id x4mr1798642pgp.282.1556772947423; Wed, 01 May 2019 21:55:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556772947; cv=none; d=google.com; s=arc-20160816; b=aScvEHfqgvSHFRfvceErqT+J4AFRzDpiPbTdHXq6h5kZbvlEeCGQgHiqoeTqmM8oFC DfPktbflVrNjmVoGqtGG5QkclltKr0RJF8DPn2YZWwNhJfrw7gXnj26AkW3peDMjX4Bu F8tsDhLKv2KOGtGYSp+oNt7mTEzBk5WjceT4PPaijf+rXQ3G2F9/IgL//qVva8gSzQDG P/MZj/nPgftd3//b0P3lkjf6tXdLcR9iTmeO2UKkVZA11+VFkqF64+eS5ZdUbto26TqR eovTNSBEZErFbx5ZSadFs69AnpBPeGSS56mqNc9VjIm/Fhj8YBo3wEMqM/CXJGuTRcB8 ZgIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=I0FeEl/w+6bt1GR2o7dyQEdLVhu5vJLVUHB5TTIyQLM=; b=oyh6gw0JTcHSqxRb8P18SK8MrIxKouHh1RvPkut8yMydgQvlZgm2Osu92k/CyGUCU9 b6ruWcueALcsX/lbsHezsQxQ3Hhetj/THede1su361LltoRNpkCFx+Eh4BWJXYjENkKT Rxco0AZfVNCIFbptfu8L6lyDsli8IsLprrrDkosXhGzQBYHH+PI7ZGnPYP9Rgb/epV71 XKnvFNNx9KuU9zwCx97ASd7LAJfQrnTcfNUkgjsWsFgjvSXmq10lDL2gCjJyKOEJh3s7 Sdh5ifzUg2byy05b3qnVWWW75c5/A4H7Y0fR8IXaJlo+7vmSM+40aZB7pbsYoNPubXlS JzBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=i34RksDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce8si21506392plb.149.2019.05.01.21.55.31; Wed, 01 May 2019 21:55:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=i34RksDU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726224AbfEBEyK (ORCPT + 99 others); Thu, 2 May 2019 00:54:10 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:62658 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbfEBEyK (ORCPT ); Thu, 2 May 2019 00:54:10 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44vjbM5M91z9v0BV; Thu, 2 May 2019 06:54:07 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=i34RksDU; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id fsoG583XIQdN; Thu, 2 May 2019 06:54:07 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44vjbM41xVz9v0BC; Thu, 2 May 2019 06:54:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1556772847; bh=I0FeEl/w+6bt1GR2o7dyQEdLVhu5vJLVUHB5TTIyQLM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=i34RksDU0m+1D9lH5cGRWzmbilcKtHDaRv5ToGo9d6faaqXA3nnFcxEChzcW4WNRj r5bQzwZP3VUqOInhA8yiITExOyffCWXBQ5nPmvz8u6fxSEPbYd9u3ZQFU2jhDEH24i N+I8zab8zf7Uaxq0qv8xBEQdzhpCBkMjYPdAdDOM= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 583318B852; Thu, 2 May 2019 06:54:08 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id fI6na7e6-yyE; Thu, 2 May 2019 06:54:08 +0200 (CEST) Received: from PO15451 (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A81188B74C; Thu, 2 May 2019 06:54:07 +0200 (CEST) Subject: Re: [PATCH v2 6/6] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init To: Rasmus Villemoes , "devicetree@vger.kernel.org" , Qiang Zhao , Li Yang Cc: "linuxppc-dev@lists.ozlabs.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Rob Herring , Scott Wood , Mark Rutland , Rasmus Villemoes References: <20190430133615.25721-1-rasmus.villemoes@prevas.dk> <20190501092841.9026-1-rasmus.villemoes@prevas.dk> <20190501092841.9026-7-rasmus.villemoes@prevas.dk> From: Christophe Leroy Message-ID: <5457d33f-b691-6406-138d-0fc633c1d24c@c-s.fr> Date: Thu, 2 May 2019 06:54:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190501092841.9026-7-rasmus.villemoes@prevas.dk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 01/05/2019 à 11:29, Rasmus Villemoes a écrit : > The comment "No QE ever has fewer than 28 SNUMs" is false; e.g. the > MPC8309 has 14. The code path returning -EINVAL is also a recipe for > instant disaster, since the caller (qe_snums_init) uncritically > assigns the return value to the unsigned qe_num_of_snum, and would > thus proceed to attempt to copy 4GB from snum_init_46[] to the snum[] > array. > > So fold the handling of the legacy fsl,qe-num-snums into > qe_snums_init, and make sure we do not end up using the snum_init_46 > array in cases other than the two where we know it makes sense. > > Signed-off-by: Rasmus Villemoes Reviewed-by: Christophe Leroy > --- > drivers/soc/fsl/qe/qe.c | 46 ++++++++++++++--------------------------- > 1 file changed, 16 insertions(+), 30 deletions(-) > > diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c > index 325d689cbf5c..276d7d78ebfc 100644 > --- a/drivers/soc/fsl/qe/qe.c > +++ b/drivers/soc/fsl/qe/qe.c > @@ -308,24 +308,33 @@ static void qe_snums_init(void) > int i; > > bitmap_zero(snum_state, QE_NUM_OF_SNUM); > + qe_num_of_snum = 28; /* The default number of snum for threads is 28 */ > qe = qe_get_device_node(); > if (qe) { > i = of_property_read_variable_u8_array(qe, "fsl,qe-snums", > snums, 1, QE_NUM_OF_SNUM); > - of_node_put(qe); > if (i > 0) { > + of_node_put(qe); > qe_num_of_snum = i; > return; > } > + /* > + * Fall back to legacy binding of using the value of > + * fsl,qe-num-snums to choose one of the static arrays > + * above. > + */ > + of_property_read_u32(qe, "fsl,qe-num-snums", &qe_num_of_snum); > + of_node_put(qe); > } > > - qe_num_of_snum = qe_get_num_of_snums(); > - > - if (qe_num_of_snum == 76) > + if (qe_num_of_snum == 76) { > snum_init = snum_init_76; > - else > + } else if (qe_num_of_snum == 28 || qe_num_of_snum == 46) { > snum_init = snum_init_46; > - > + } else { > + pr_err("QE: unsupported value of fsl,qe-num-snums: %u\n", qe_num_of_snum); > + return; > + } > memcpy(snums, snum_init, qe_num_of_snum); > } > > @@ -641,30 +650,7 @@ EXPORT_SYMBOL(qe_get_num_of_risc); > > unsigned int qe_get_num_of_snums(void) > { > - struct device_node *qe; > - int size; > - unsigned int num_of_snums; > - const u32 *prop; > - > - num_of_snums = 28; /* The default number of snum for threads is 28 */ > - qe = qe_get_device_node(); > - if (!qe) > - return num_of_snums; > - > - prop = of_get_property(qe, "fsl,qe-num-snums", &size); > - if (prop && size == sizeof(*prop)) { > - num_of_snums = *prop; > - if ((num_of_snums < 28) || (num_of_snums > QE_NUM_OF_SNUM)) { > - /* No QE ever has fewer than 28 SNUMs */ > - pr_err("QE: number of snum is invalid\n"); > - of_node_put(qe); > - return -EINVAL; > - } > - } > - > - of_node_put(qe); > - > - return num_of_snums; > + return qe_num_of_snum; > } > EXPORT_SYMBOL(qe_get_num_of_snums); > >