All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Wahren <wahrenst@gmx.net>
To: Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>
Cc: "Maxime Ripard" <mripard@kernel.org>,
	"Mylène Josserand" <mylene.josserand@bootlin.com>,
	linux-sunxi@lists.linux.dev, soc@kernel.org,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	linux-arm-kernel@lists.infradead.org,
	"Stefan Wahren" <wahrenst@gmx.net>,
	"Nick Desaulniers" <ndesaulniers@google.com>
Subject: [PATCH V2 2/2] ARM: sun9i: smp: fix return code check of of_property_match_string
Date: Thu, 28 Dec 2023 20:39:03 +0100	[thread overview]
Message-ID: <20231228193903.9078-2-wahrenst@gmx.net> (raw)
In-Reply-To: <20231228193903.9078-1-wahrenst@gmx.net>

of_property_match_string returns an int; either an index from 0 or
greater if successful or negative on failure. Even it's very
unlikely that the DT CPU node contains multiple enable-methods
these checks should be fixed.

This patch was inspired by the work of Nick Desaulniers.

Link: https://lore.kernel.org/lkml/20230516-sunxi-v1-1-ac4b9651a8c1@google.com/T/
Cc: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 arch/arm/mach-sunxi/mc_smp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-sunxi/mc_smp.c b/arch/arm/mach-sunxi/mc_smp.c
index 6ec3445f3c72..277f6aa8e6c2 100644
--- a/arch/arm/mach-sunxi/mc_smp.c
+++ b/arch/arm/mach-sunxi/mc_smp.c
@@ -803,12 +803,12 @@ static int __init sunxi_mc_smp_init(void)
 	for (i = 0; i < ARRAY_SIZE(sunxi_mc_smp_data); i++) {
 		ret = of_property_match_string(node, "enable-method",
 					       sunxi_mc_smp_data[i].enable_method);
-		if (!ret)
+		if (ret >= 0)
 			break;
 	}

 	of_node_put(node);
-	if (ret)
+	if (ret < 0)
 		return -ENODEV;

 	is_a83t = sunxi_mc_smp_data[i].is_a83t;
--
2.34.1


WARNING: multiple messages have this Message-ID (diff)
From: Stefan Wahren <wahrenst@gmx.net>
To: Chen-Yu Tsai <wens@csie.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	Samuel Holland <samuel@sholland.org>
Cc: "Maxime Ripard" <mripard@kernel.org>,
	"Mylène Josserand" <mylene.josserand@bootlin.com>,
	linux-sunxi@lists.linux.dev, soc@kernel.org,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	linux-arm-kernel@lists.infradead.org,
	"Stefan Wahren" <wahrenst@gmx.net>,
	"Nick Desaulniers" <ndesaulniers@google.com>
Subject: [PATCH V2 2/2] ARM: sun9i: smp: fix return code check of of_property_match_string
Date: Thu, 28 Dec 2023 20:39:03 +0100	[thread overview]
Message-ID: <20231228193903.9078-2-wahrenst@gmx.net> (raw)
In-Reply-To: <20231228193903.9078-1-wahrenst@gmx.net>

of_property_match_string returns an int; either an index from 0 or
greater if successful or negative on failure. Even it's very
unlikely that the DT CPU node contains multiple enable-methods
these checks should be fixed.

This patch was inspired by the work of Nick Desaulniers.

Link: https://lore.kernel.org/lkml/20230516-sunxi-v1-1-ac4b9651a8c1@google.com/T/
Cc: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Stefan Wahren <wahrenst@gmx.net>
---
 arch/arm/mach-sunxi/mc_smp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-sunxi/mc_smp.c b/arch/arm/mach-sunxi/mc_smp.c
index 6ec3445f3c72..277f6aa8e6c2 100644
--- a/arch/arm/mach-sunxi/mc_smp.c
+++ b/arch/arm/mach-sunxi/mc_smp.c
@@ -803,12 +803,12 @@ static int __init sunxi_mc_smp_init(void)
 	for (i = 0; i < ARRAY_SIZE(sunxi_mc_smp_data); i++) {
 		ret = of_property_match_string(node, "enable-method",
 					       sunxi_mc_smp_data[i].enable_method);
-		if (!ret)
+		if (ret >= 0)
 			break;
 	}

 	of_node_put(node);
-	if (ret)
+	if (ret < 0)
 		return -ENODEV;

 	is_a83t = sunxi_mc_smp_data[i].is_a83t;
--
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-12-28 19:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-28 19:39 [PATCH V2 1/2] ARM: sun9i: smp: Fix array-index-out-of-bounds read in sunxi_mc_smp_init Stefan Wahren
2023-12-28 19:39 ` Stefan Wahren
2023-12-28 19:39 ` Stefan Wahren [this message]
2023-12-28 19:39   ` [PATCH V2 2/2] ARM: sun9i: smp: fix return code check of of_property_match_string Stefan Wahren
2024-01-02 14:59   ` Chen-Yu Tsai
2024-01-02 14:59     ` Chen-Yu Tsai
2024-01-02 15:49     ` Arnd Bergmann
2024-01-02 15:49       ` Arnd Bergmann
2024-01-02 10:11 ` [PATCH V2 1/2] ARM: sun9i: smp: Fix array-index-out-of-bounds read in sunxi_mc_smp_init patchwork-bot+linux-soc
2024-01-02 14:58 ` Chen-Yu Tsai
2024-01-02 14:58   ` Chen-Yu Tsai

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=20231228193903.9078-2-wahrenst@gmx.net \
    --to=wahrenst@gmx.net \
    --cc=arnd@arndb.de \
    --cc=f.fainelli@gmail.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mripard@kernel.org \
    --cc=mylene.josserand@bootlin.com \
    --cc=ndesaulniers@google.com \
    --cc=samuel@sholland.org \
    --cc=soc@kernel.org \
    --cc=wens@csie.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.