* [PATCH next v2] spi: Fix potential uninitialized variable in probe()
@ 2025-11-24 7:56 Dan Carpenter
2025-11-24 15:00 ` Prajna Rajendra Kumar
2025-11-24 19:15 ` Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-11-24 7:56 UTC (permalink / raw)
To: Prajna Rajendra Kumar
Cc: Mark Brown, Conor Dooley, linux-spi, linux-kernel,
kernel-janitors
If the device tree is messed up, then potentially the "protocol" string
could potentially be uninitialized. The property is supposed to default
to "motorola" so if the of_property_read_string() function returns
-EINVAL then default to "motorola".
Fixes: 059f545832be ("spi: add support for microchip "soft" spi controller")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: Add an error message on failure.
Default to "motorola".
drivers/spi/spi-microchip-core-spi.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c
index b8738190cdcb..16e0885474a0 100644
--- a/drivers/spi/spi-microchip-core-spi.c
+++ b/drivers/spi/spi-microchip-core-spi.c
@@ -295,10 +295,10 @@ static int mchp_corespi_transfer_one(struct spi_controller *host,
static int mchp_corespi_probe(struct platform_device *pdev)
{
+ const char *protocol = "motorola";
struct spi_controller *host;
struct mchp_corespi *spi;
struct resource *res;
- const char *protocol;
u32 num_cs, mode, frame_size;
bool assert_ssel;
int ret = 0;
@@ -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 && ret != -EINVAL)
+ return dev_err_probe(&pdev->dev, ret, "Error reading protocol-configuration\n");
if (strcmp(protocol, "motorola") != 0)
return dev_err_probe(&pdev->dev, -EINVAL,
"CoreSPI: protocol '%s' not supported by this driver\n",
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH next v2] spi: Fix potential uninitialized variable in probe()
2025-11-24 7:56 [PATCH next v2] spi: Fix potential uninitialized variable in probe() Dan Carpenter
@ 2025-11-24 15:00 ` Prajna Rajendra Kumar
2025-11-24 19:15 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Prajna Rajendra Kumar @ 2025-11-24 15:00 UTC (permalink / raw)
To: Dan Carpenter
Cc: Mark Brown, Conor Dooley, linux-spi, linux-kernel,
kernel-janitors
On 24/11/2025 07:56, Dan Carpenter wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> If the device tree is messed up, then potentially the "protocol" string
> could potentially be uninitialized. The property is supposed to default
> to "motorola" so if the of_property_read_string() function returns
> -EINVAL then default to "motorola".
>
> Fixes: 059f545832be ("spi: add support for microchip "soft" spi controller")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Prajna Rajendra Kumar <prajna.rajendrakumar@microchip.com>
> ---
> v2: Add an error message on failure.
> Default to "motorola".
>
> drivers/spi/spi-microchip-core-spi.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-microchip-core-spi.c b/drivers/spi/spi-microchip-core-spi.c
> index b8738190cdcb..16e0885474a0 100644
> --- a/drivers/spi/spi-microchip-core-spi.c
> +++ b/drivers/spi/spi-microchip-core-spi.c
> @@ -295,10 +295,10 @@ static int mchp_corespi_transfer_one(struct spi_controller *host,
>
> static int mchp_corespi_probe(struct platform_device *pdev)
> {
> + const char *protocol = "motorola";
> struct spi_controller *host;
> struct mchp_corespi *spi;
> struct resource *res;
> - const char *protocol;
> u32 num_cs, mode, frame_size;
> bool assert_ssel;
> int ret = 0;
> @@ -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 && ret != -EINVAL)
> + return dev_err_probe(&pdev->dev, ret, "Error reading protocol-configuration\n");
> if (strcmp(protocol, "motorola") != 0)
> return dev_err_probe(&pdev->dev, -EINVAL,
> "CoreSPI: protocol '%s' not supported by this driver\n",
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH next v2] spi: Fix potential uninitialized variable in probe()
2025-11-24 7:56 [PATCH next v2] spi: Fix potential uninitialized variable in probe() Dan Carpenter
2025-11-24 15:00 ` Prajna Rajendra Kumar
@ 2025-11-24 19:15 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2025-11-24 19:15 UTC (permalink / raw)
To: Prajna Rajendra Kumar, Dan Carpenter
Cc: Conor Dooley, linux-spi, linux-kernel, kernel-janitors
On Mon, 24 Nov 2025 10:56:01 +0300, Dan Carpenter wrote:
> If the device tree is messed up, then potentially the "protocol" string
> could potentially be uninitialized. The property is supposed to default
> to "motorola" so if the of_property_read_string() function returns
> -EINVAL then default to "motorola".
>
>
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: Fix potential uninitialized variable in probe()
commit: cb99656b7c4185953c9d272bbdab63c8aa651e6e
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-24 19:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24 7:56 [PATCH next v2] spi: Fix potential uninitialized variable in probe() Dan Carpenter
2025-11-24 15:00 ` Prajna Rajendra Kumar
2025-11-24 19:15 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox