From: Conor Dooley <conor@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
Prajna Rajendra Kumar <prajna.rajendrakumar@microchip.com>,
Conor Dooley <conor.dooley@microchip.com>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH next] spi: Fix potential uninitialized variable in probe()
Date: Fri, 21 Nov 2025 16:20:41 +0000 [thread overview]
Message-ID: <20251121-apostle-stark-7af8aebfe9c1@spud> (raw)
In-Reply-To: <cd3dc38e-72f6-4e83-a67f-266523e686f1@sirena.org.uk>
[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]
On Fri, Nov 21, 2025 at 02:18:49PM +0000, Mark Brown wrote:
> On Fri, Nov 21, 2025 at 04:35:01PM +0300, Dan Carpenter wrote:
> > If the device tree is messed up, then potentially the "protocol" string
> > could potentially be uninitialized. Add a check to prevent that.
> >
> > Fixes: 059f545832be ("spi: add support for microchip "soft" spi controller")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> > drivers/spi/spi-microchip-core-spi.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c
> > index b8738190cdcb..e65036cc62f3 100644
> > --- a/drivers/spi/spi-microchip-core-spi.c
> > +++ b/drivers/spi/spi-microchip-core-spi.c
> > @@ -320,6 +320,8 @@ static int mchp_corespi_probe(struct platform_device *pdev)
> > */
> > ret = of_property_read_string(pdev->dev.of_node, "microchip,protocol-configuration",
> > &protocol);
> > + if (ret)
> > + return ret;
> > if (strcmp(protocol, "motorola") != 0)
> > return dev_err_probe(&pdev->dev, -EINVAL,
> > "CoreSPI: protocol '%s' not supported by this driver\n",
>
> This should probably also complain about not being able to get the
> property, otherwise nobody is going to be able to figure out what's
> wrong if we actually hit the error case.
The one thing to be careful of is that the property has a default, so
EINVAL needs to be treated differently, so the decision tree is
something like:
if (ret == _EINVAL)
<do nothing>
else if (ret)
abort complaining about malformed
else if (!motorola)
abort complaining about unsupported mode
else
<do nothing>
obviously that can just become two clauses, but you get the idea.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-11-21 16:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 13:35 [PATCH next] spi: Fix potential uninitialized variable in probe() Dan Carpenter
2025-11-21 14:18 ` Mark Brown
2025-11-21 16:20 ` Conor Dooley [this message]
2025-11-24 7:56 ` Dan Carpenter
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=20251121-apostle-stark-7af8aebfe9c1@spud \
--to=conor@kernel.org \
--cc=broonie@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=dan.carpenter@linaro.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=prajna.rajendrakumar@microchip.com \
/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