diff mbox

spi - Fix possible NULL derefrence.

Message ID 1485752113-29581-1-git-send-email-shailendra.v@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

shailendra.v@samsung.com Jan. 30, 2017, 4:55 a.m. UTC
of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 drivers/spi/spi-mxs.c |    5 +++++
 1 file changed, 5 insertions(+)

Comments

Geert Uytterhoeven Jan. 30, 2017, 10 a.m. UTC | #1
Hi Shailendra,

On Mon, Jan 30, 2017 at 5:55 AM, Shailendra Verma
<shailendra.v@samsung.com> wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.

Can it? The driver uses DT exclusively.
There is no legacy platform code creating "mxs-spi" platform devices.

> Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
> ---
>  drivers/spi/spi-mxs.c |    5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
> index 5b0e9a3..c3aea7e 100644
> --- a/drivers/spi/spi-mxs.c
> +++ b/drivers/spi/spi-mxs.c
> @@ -470,6 +470,11 @@ static int mxs_spi_probe(struct platform_device *pdev)
>          */
>         const int clk_freq_default = 160000000;
>
> +       if (!of_id) {
> +               dev_err(&pdev->dev, "Error: No device match found\n");
> +               return -ENODEV;
> +       }
> +

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mark Brown Jan. 30, 2017, 12:52 p.m. UTC | #2
On Mon, Jan 30, 2017 at 11:00:28AM +0100, Geert Uytterhoeven wrote:
> On Mon, Jan 30, 2017 at 5:55 AM, Shailendra Verma
> <shailendra.v@samsung.com> wrote:
> > of_match_device could return NULL, and so can cause a NULL
> > pointer dereference later.

> Can it? The driver uses DT exclusively.
> There is no legacy platform code creating "mxs-spi" platform devices.

Yeah, the changelogs on these aren't very good - there's no present
risk, though future changes could potentially cause an issue so it's not
unreasonable to do it defensively.
diff mbox

Patch

diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
index 5b0e9a3..c3aea7e 100644
--- a/drivers/spi/spi-mxs.c
+++ b/drivers/spi/spi-mxs.c
@@ -470,6 +470,11 @@  static int mxs_spi_probe(struct platform_device *pdev)
 	 */
 	const int clk_freq_default = 160000000;
 
+	if (!of_id) {
+		dev_err(&pdev->dev, "Error: No device match found\n");
+		return -ENODEV;
+	}
+
 	iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	irq_err = platform_get_irq(pdev, 0);
 	if (irq_err < 0)