From: Kangjie Lu <kjlu@umn.edu>
To: kjlu@umn.edu
Cc: pakki001@umn.edu, Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] iio: hmc5843_spi: fix a NULL pointer dereference
Date: Sat, 9 Mar 2019 12:56:27 -0600 [thread overview]
Message-ID: <20190309185628.21059-1-kjlu@umn.edu> (raw)
In case devm_regmap_init_spi fails and returns NULL, the fix
returns an error to avoid NULL pointer dereference
Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
drivers/iio/magnetometer/hmc5843_spi.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c
index 535f03a70d63..15e2f7cbb3b5 100644
--- a/drivers/iio/magnetometer/hmc5843_spi.c
+++ b/drivers/iio/magnetometer/hmc5843_spi.c
@@ -59,6 +59,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
{
int ret;
const struct spi_device_id *id = spi_get_device_id(spi);
+ struct regmap *devm_regmap = devm_regmap_init_spi(spi,
+ &hmc5843_spi_regmap_config);
+
+ if (IS_ERR(devm_regmap))
+ return PTR_ERR(devm_regmap);
+
spi->mode = SPI_MODE_3;
spi->max_speed_hz = 8000000;
@@ -68,7 +74,7 @@ static int hmc5843_spi_probe(struct spi_device *spi)
return ret;
return hmc5843_common_probe(&spi->dev,
- devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
+ devm_regmap,
id->driver_data, id->name);
}
--
2.17.1
next reply other threads:[~2019-03-09 18:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-09 18:56 Kangjie Lu [this message]
2019-03-10 10:26 ` [PATCH] iio: hmc5843_spi: fix a NULL pointer dereference Jonathan Cameron
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=20190309185628.21059-1-kjlu@umn.edu \
--to=kjlu@umn.edu \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pakki001@umn.edu \
--cc=pmeerw@pmeerw.net \
/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