linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Arch: arm: plat-pxa - Fix possible NULL derefrence.
       [not found] <CGME20170130045842epcas2p274b2125a1f158e4d656096bdf3a3a1d9@epcas2p2.samsung.com>
@ 2017-01-30  4:58 ` Shailendra Verma
  2017-01-30 19:08   ` Russell King - ARM Linux
  0 siblings, 1 reply; 2+ messages in thread
From: Shailendra Verma @ 2017-01-30  4:58 UTC (permalink / raw)
  To: Russell King, linux-arm-kernel, linux-kernel, p.shailesh,
	ashish.kalra, Shailendra Verma, Shailendra Verma

of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 arch/arm/plat-pxa/ssp.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/plat-pxa/ssp.c b/arch/arm/plat-pxa/ssp.c
index ba13f79..7d1cd51 100644
--- a/arch/arm/plat-pxa/ssp.c
+++ b/arch/arm/plat-pxa/ssp.c
@@ -204,6 +204,10 @@ static int pxa_ssp_probe(struct platform_device *pdev)
 	if (dev->of_node) {
 		const struct of_device_id *id =
 			of_match_device(of_match_ptr(pxa_ssp_of_ids), dev);
+		if (!id) {
+			dev_err(dev, "Error: No device match found\n");
+			return -ENODEV;
+		}
 		ssp->type = (int) id->data;
 	} else {
 		const struct platform_device_id *id =
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Arch: arm: plat-pxa - Fix possible NULL derefrence.
  2017-01-30  4:58 ` [PATCH] Arch: arm: plat-pxa - Fix possible NULL derefrence Shailendra Verma
@ 2017-01-30 19:08   ` Russell King - ARM Linux
  0 siblings, 0 replies; 2+ messages in thread
From: Russell King - ARM Linux @ 2017-01-30 19:08 UTC (permalink / raw)
  To: Shailendra Verma
  Cc: linux-arm-kernel, linux-kernel, p.shailesh, ashish.kalra,
	Shailendra Verma

On Mon, Jan 30, 2017 at 10:28:31AM +0530, Shailendra Verma wrote:
> of_match_device could return NULL, and so can cause a NULL
> pointer dereference later.

Please explain how this can happen.

The driver is matched to the device via the driver model looking up
the compatible string in the match table:

                .of_match_table = of_match_ptr(pxa_ssp_of_ids),

It then calls the probe function, which notices that there's a DT
node pointer, and the driver looks the device up in the very same
table.

If the driver model found a match and then the device driver didn't
for the very same device, something really bad went wrong.

So, if you want to add something:

	if (WARN_ON(!id))
		return -ENODEV;

should be about it, since it's something we expect to never encounter.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-30 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20170130045842epcas2p274b2125a1f158e4d656096bdf3a3a1d9@epcas2p2.samsung.com>
2017-01-30  4:58 ` [PATCH] Arch: arm: plat-pxa - Fix possible NULL derefrence Shailendra Verma
2017-01-30 19:08   ` Russell King - ARM Linux

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).