From: "Clément Le Goffic" <clement.legoffic@foss.st.com>
To: "Alain Volmat" <alain.volmat@foss.st.com>,
"Mark Brown" <broonie@kernel.org>,
"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
"Valentin Caron" <valentin.caron@foss.st.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Erwan Leray" <erwan.leray@foss.st.com>,
"Fabrice Gasnier" <fabrice.gasnier@foss.st.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>
Cc: linux-spi@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org,
"Clément Le Goffic" <clement.legoffic@foss.st.com>,
"kernel test robot" <lkp@intel.com>
Subject: [PATCH 2/6] spi: stm32: Check for cfg availability in stm32_spi_probe
Date: Mon, 16 Jun 2025 11:21:03 +0200 [thread overview]
Message-ID: <20250616-spi-upstream-v1-2-7e8593f3f75d@foss.st.com> (raw)
In-Reply-To: <20250616-spi-upstream-v1-0-7e8593f3f75d@foss.st.com>
The stm32_spi_probe function now includes a check to ensure that the
pointer returned by of_device_get_match_data is not NULL before
accessing its members. This resolves a warning where a potential NULL
pointer dereference could occur when accessing cfg->has_device_mode.
Before accessing the 'has_device_mode' member, we verify that 'cfg' is
not NULL. If 'cfg' is NULL, an error message is logged.
This change ensures that the driver does not attempt to access
configuration data if it is not available, thus preventing a potential
system crash due to a NULL pointer dereference.
Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310191831.MLwx1c6x-lkp@intel.com/
Fixes: fee681646fc8 ("spi: stm32: disable device mode with st,stm32f4-spi compatible")
---
drivers/spi/spi-stm32.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 2bcd4a43676d..8b61caf770a2 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -2089,9 +2089,15 @@ static int stm32_spi_probe(struct platform_device *pdev)
struct resource *res;
struct reset_control *rst;
struct device_node *np = pdev->dev.of_node;
+ const struct stm32_spi_cfg *cfg;
bool device_mode;
int ret;
- const struct stm32_spi_cfg *cfg = of_device_get_match_data(&pdev->dev);
+
+ cfg = of_device_get_match_data(&pdev->dev);
+ if (!cfg) {
+ dev_err(&pdev->dev, "Failed to get match data for platform\n");
+ return -ENODEV;
+ }
device_mode = of_property_read_bool(np, "spi-slave");
if (!cfg->has_device_mode && device_mode) {
--
2.43.0
next prev parent reply other threads:[~2025-06-16 9:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 9:21 [PATCH 0/6] Add few updates to the STM32 SPI driver Clément Le Goffic
2025-06-16 9:21 ` [PATCH 1/6] spi: stm32: Add SPI_READY mode to spi controller Clément Le Goffic
2025-06-16 9:21 ` Clément Le Goffic [this message]
2025-06-16 9:21 ` [PATCH 3/6] dt-bindings: spi: stm32: update bindings with SPI Rx DMA-MDMA chaining Clément Le Goffic
2025-06-16 9:21 ` [PATCH 4/6] spi: stm32: use STM32 DMA with STM32 MDMA to enhance DDR use Clément Le Goffic
2025-06-16 9:21 ` [PATCH 5/6] spi: stm32: deprecate `st,spi-midi-ns` property Clément Le Goffic
2025-06-16 9:21 ` [PATCH 6/6] dt-bindings: " Clément Le Goffic
2025-06-25 19:12 ` [PATCH 0/6] Add few updates to the STM32 SPI driver Mark Brown
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=20250616-spi-upstream-v1-2-7e8593f3f75d@foss.st.com \
--to=clement.legoffic@foss.st.com \
--cc=alain.volmat@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=broonie@kernel.org \
--cc=christian.koenig@amd.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=erwan.leray@foss.st.com \
--cc=fabrice.gasnier@foss.st.com \
--cc=krzk+dt@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=lkp@intel.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=valentin.caron@foss.st.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;
as well as URLs for NNTP newsgroup(s).