From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
To: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
Qiang Zhao <qiang.zhao@nxp.com>, Li Yang <leoyang.li@nxp.com>
Cc: "linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Rob Herring <robh+dt@kernel.org>, Scott Wood <oss@buserror.net>,
Christophe Leroy <christophe.leroy@c-s.fr>,
Mark Rutland <mark.rutland@arm.com>,
Joakim Tjernlund <Joakim.Tjernlund@infinera.com>,
Rasmus Villemoes <Rasmus.Villemoes@prevas.se>
Subject: [PATCH v3 6/6] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init
Date: Mon, 13 May 2019 11:15:01 +0000 [thread overview]
Message-ID: <20190513111442.25724-7-rasmus.villemoes@prevas.dk> (raw)
In-Reply-To: <20190513111442.25724-1-rasmus.villemoes@prevas.dk>
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.
Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr>
Reviewed-by: Qiang Zhao <qiang.zhao@nxp.com>
Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---
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 1d27187b251c..852060caff24 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);
}
@@ -642,30 +651,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);
--
2.20.1
next prev parent reply other threads:[~2019-05-13 11:15 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-30 13:36 [PATCH RESEND 0/5] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-04-30 13:36 ` [PATCH 1/5] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-04-30 17:03 ` Christophe Leroy
2019-04-30 13:36 ` [PATCH 2/5] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
2019-04-30 17:12 ` Christophe Leroy
2019-05-01 5:51 ` Rasmus Villemoes
2019-04-30 13:36 ` [PATCH 3/5] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-04-30 17:14 ` Christophe Leroy
2019-04-30 13:36 ` [PATCH 4/5] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
2019-04-30 17:19 ` Christophe Leroy
2019-05-01 6:00 ` Rasmus Villemoes
2019-04-30 13:36 ` [PATCH 5/5] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init Rasmus Villemoes
2019-04-30 17:27 ` Christophe Leroy
2019-05-01 9:29 ` [PATCH v2 0/6] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-05-01 9:29 ` [PATCH v2 1/6] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-05-01 9:29 ` [PATCH v2 2/6] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
2019-05-02 4:51 ` Christophe Leroy
2019-05-01 9:29 ` [PATCH v2 3/6] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-05-01 9:29 ` [PATCH v2 4/6] dt-bindings: soc/fsl: qe: document new fsl,qe-snums binding Rasmus Villemoes
2019-05-01 15:12 ` Joakim Tjernlund
2019-05-01 18:47 ` Rasmus Villemoes
2019-05-01 21:00 ` Rob Herring
2019-05-01 9:29 ` [PATCH v2 5/6] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
2019-05-02 4:52 ` Christophe Leroy
2019-05-01 9:29 ` [PATCH v2 6/6] soc/fsl/qe: qe.c: fold qe_get_num_of_snums into qe_snums_init Rasmus Villemoes
2019-05-02 4:54 ` Christophe Leroy
2019-05-09 2:35 ` [EXT] " Qiang Zhao
2019-05-13 11:14 ` [PATCH v3 0/6] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-05-13 11:14 ` [PATCH v3 1/6] soc/fsl/qe: qe.c: drop useless static qualifier Rasmus Villemoes
2019-05-13 11:14 ` [PATCH v3 2/6] soc/fsl/qe: qe.c: reduce static memory footprint by 1.7K Rasmus Villemoes
2019-05-13 11:14 ` [PATCH v3 3/6] soc/fsl/qe: qe.c: introduce qe_get_device_node helper Rasmus Villemoes
2019-05-13 11:14 ` [PATCH v3 4/6] dt-bindings: soc/fsl: qe: document new fsl,qe-snums binding Rasmus Villemoes
2019-05-13 11:39 ` Joakim Tjernlund
2019-05-13 17:51 ` Rob Herring
2019-05-13 11:15 ` [PATCH v3 5/6] soc/fsl/qe: qe.c: support fsl,qe-snums property Rasmus Villemoes
2019-05-13 11:15 ` Rasmus Villemoes [this message]
2019-06-03 19:53 ` [PATCH v3 0/6] soc/fsl/qe: cleanups and new DT binding Rasmus Villemoes
2019-06-03 19:55 ` Leo Li
2019-06-04 20:29 ` Li Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190513111442.25724-7-rasmus.villemoes@prevas.dk \
--to=rasmus.villemoes@prevas.dk \
--cc=Joakim.Tjernlund@infinera.com \
--cc=Rasmus.Villemoes@prevas.se \
--cc=christophe.leroy@c-s.fr \
--cc=devicetree@vger.kernel.org \
--cc=leoyang.li@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mark.rutland@arm.com \
--cc=oss@buserror.net \
--cc=qiang.zhao@nxp.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).