Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5186288yba; Tue, 30 Apr 2019 10:28:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZRlC1hZcFszC+NoiuGiIABMVxJcF4atvuk6htG6ciHM/c079OYVjC2w+E+gtYAaXNLcbX X-Received: by 2002:aa7:9148:: with SMTP id 8mr41244473pfi.176.1556645327815; Tue, 30 Apr 2019 10:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556645327; cv=none; d=google.com; s=arc-20160816; b=uUiewtQPtwSG9nTzFl/utpoLsUacbTZpSj+MmOxozsPudgEF8xiHPANzRQM/6Bj9bm GTa2zVWQM1YQs7wks84C2f3C5yBlhYmHcSvTj+YaWq3t6KDymSQG0B9ChFprlhQ8I3sE ySLS1J6CYYX/CVgnyfD0GM98xF+Q8U66V10e17HsX55Ls6Pjw9iaPs55b7CXmHjZXwkh +MWUB1nhFGvmcmKweB8sRBrUOvLELiv8j3KWdkdEH5UrA5MomkTOKLpyQ5KtyYqQXOwv wzw36+bNNloJAshEuz2cgHqu0cYACnkyqdDgxsPghkYGUnzUr5MCSNAt7Xw2CqybDK3H O/wg== 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=CiyJsTqHm5VKfq00rEpHJAK9KzqoqbhlzPXSaD1Lpgg=; b=EMyHW/RSxwmhRQRH/eQ0AhTgHhc+vOz3oDRLYLDNrgnRkie0I4lyS2ZEzZPumv91Xm BEGuqCHrBdVmwQ+d4wDI42GXhkIjlpOvNtGekAKZkuv/E/iEElr9ijBZ3WclDQPVVx8f 7ZWqtxW5naLBVQTiYxvXW1pcVryuiUDMEYtwpTegSVELJehaXz/t5sfsjwU6m7nl5s47 yEQZ5/P6zpkUl9429rVzgOKMYP0FkiTgXDcE0gLs7UP5WqDUYO2+vJpQDH38hvLg8zTn BJjZDhndjkcZTFdHMmNG4cM7Dj1itEMlJRFqznXCoEDr2OlJBRXPYFpiDJ7meNp1/BeD Lpvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=ujTQdwmK; 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 i20si4495400pfr.279.2019.04.30.10.28.32; Tue, 30 Apr 2019 10:28: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=ujTQdwmK; 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 S1726839AbfD3R1R (ORCPT + 99 others); Tue, 30 Apr 2019 13:27:17 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:45351 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726804AbfD3R1Q (ORCPT ); Tue, 30 Apr 2019 13:27:16 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44tpPF1kWvz9vB2f; Tue, 30 Apr 2019 19:27:13 +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=ujTQdwmK; 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 SKPy5gPho9In; Tue, 30 Apr 2019 19:27:13 +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 44tpPF0PWvz9vB2d; Tue, 30 Apr 2019 19:27:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1556645233; bh=CiyJsTqHm5VKfq00rEpHJAK9KzqoqbhlzPXSaD1Lpgg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ujTQdwmKpxAV2UodghfYbrsSATH3/PVUAoOrjQfQUYNrxXSxkIp4zrCYatyJo5LNR 9hZz+mTp+IkfkVh4yB6psaCKP1wkDe9JZFK65y9UmS3QTr+rtd7eAWziXs7ROr3wb3 UQUC/+jpg8SYsMhJp94oYo+R5SCpGUxeEyPcAXPU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B88F98B8F3; Tue, 30 Apr 2019 19:27:14 +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 ch6gyJW-WEhM; Tue, 30 Apr 2019 19:27:14 +0200 (CEST) Received: from PO15451 (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 100C68B8DF; Tue, 30 Apr 2019 19:27:14 +0200 (CEST) Subject: Re: [PATCH 5/5] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init To: Rasmus Villemoes , Qiang Zhao , Li Yang Cc: Valentin Longchamp , "linux-kernel@vger.kernel.org" , Scott Wood , Rasmus Villemoes , Rob Herring , "linuxppc-dev@lists.ozlabs.org" , "linux-arm-kernel@lists.infradead.org" References: <20190430133615.25721-1-rasmus.villemoes@prevas.dk> <20190430133615.25721-6-rasmus.villemoes@prevas.dk> From: Christophe Leroy Message-ID: <35a50a5b-061c-236a-16ff-0389bf34d736@c-s.fr> Date: Tue, 30 Apr 2019 19:27:13 +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: <20190430133615.25721-6-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 30/04/2019 à 15:36, 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 > --- > drivers/net/ethernet/freescale/ucc_geth.c | 2 +- > drivers/soc/fsl/qe/qe.c | 54 +++++++---------------- > include/soc/fsl/qe/qe.h | 2 +- > 3 files changed, 19 insertions(+), 39 deletions(-) > > diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c > index eb3e65e8868f..5748eb8464d0 100644 > --- a/drivers/net/ethernet/freescale/ucc_geth.c > +++ b/drivers/net/ethernet/freescale/ucc_geth.c > @@ -3837,7 +3837,7 @@ static int ucc_geth_probe(struct platform_device* ofdev) > } > > if (max_speed == SPEED_1000) { > - unsigned int snums = qe_get_num_of_snums(); > + unsigned int snums = qe_num_of_snum; > > /* configure muram FIFOs for gigabit operation */ > ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT; > diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c > index af3c2b2b268f..8c3b3c62d81b 100644 > --- a/drivers/soc/fsl/qe/qe.c > +++ b/drivers/soc/fsl/qe/qe.c > @@ -52,7 +52,8 @@ EXPORT_SYMBOL(qe_immr); > > static u8 snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */ > static DECLARE_BITMAP(snum_state, QE_NUM_OF_SNUM); > -static unsigned int qe_num_of_snum; > +unsigned int qe_num_of_snum; > +EXPORT_SYMBOL(qe_num_of_snum); By exporting the object you allow other drivers to modify it. Is that really what we want ? Why not keep qe_get_num_of_snums() as a helper that simply returns qe_num_of_snum ? > > static phys_addr_t qebase = -1; > > @@ -308,26 +309,34 @@ 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) > snum_init = snum_init_76; > - else > + else if (qe_num_of_snum == 28 || qe_num_of_snum == 46) > snum_init = snum_init_46; > - > - for (i = 0; i < qe_num_of_snum; i++) > - snums[i] = snum_init[i]; > + else { > + pr_err("QE: unsupported value of fsl,qe-num-snums: %u\n", qe_num_of_snum); > + return; > + } The first leg of the if/else must have {} too when the second leg has them. > + memcpy(snums, snum_init, qe_num_of_snum); > } > > int qe_get_snum(void) > @@ -645,35 +654,6 @@ unsigned int qe_get_num_of_risc(void) > } > EXPORT_SYMBOL(qe_get_num_of_risc); > > -unsigned int qe_get_num_of_snums(void) I think this function should remain and just return num_of_snums, see my other comment above. Christophe > -{ > - 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; > -} > -EXPORT_SYMBOL(qe_get_num_of_snums); > - > static int __init qe_init(void) > { > struct device_node *np; > diff --git a/include/soc/fsl/qe/qe.h b/include/soc/fsl/qe/qe.h > index b3d1aff5e8ad..af5739850bf4 100644 > --- a/include/soc/fsl/qe/qe.h > +++ b/include/soc/fsl/qe/qe.h > @@ -212,7 +212,7 @@ int qe_setbrg(enum qe_clock brg, unsigned int rate, unsigned int multiplier); > int qe_get_snum(void); > void qe_put_snum(u8 snum); > unsigned int qe_get_num_of_risc(void); > -unsigned int qe_get_num_of_snums(void); > +extern unsigned int qe_num_of_snum; > > static inline int qe_alive_during_sleep(void) > { >