diff mbox

[3/3] pinctrl: tegra-xusb: Check that of_match_node returns a valid pointer

Message ID 1432044863-2035-4-git-send-email-jonathanh@nvidia.com
State New
Headers show

Commit Message

Jon Hunter May 19, 2015, 2:14 p.m. UTC
of_match_node() will return NULL if no match is found and so check for
this before dereferencing the pointer.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
 drivers/pinctrl/pinctrl-tegra-xusb.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Thierry Reding May 19, 2015, 2:18 p.m. UTC | #1
On Tue, May 19, 2015 at 03:14:23PM +0100, Jon Hunter wrote:
> of_match_node() will return NULL if no match is found and so check for
> this before dereferencing the pointer.
> 
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> ---
>  drivers/pinctrl/pinctrl-tegra-xusb.c | 3 +++
>  1 file changed, 3 insertions(+)

This isn't necessary. The driver is probed from DT only and therefore
.probe() will only be called if there's a matching entry in the OF
device ID table. match can never be NULL.

Thierry
Jon Hunter May 19, 2015, 2:29 p.m. UTC | #2
On 19/05/15 15:18, Thierry Reding wrote:
> * PGP Signed by an unknown key
> 
> On Tue, May 19, 2015 at 03:14:23PM +0100, Jon Hunter wrote:
>> of_match_node() will return NULL if no match is found and so check for
>> this before dereferencing the pointer.
>>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>> ---
>>  drivers/pinctrl/pinctrl-tegra-xusb.c | 3 +++
>>  1 file changed, 3 insertions(+)
> 
> This isn't necessary. The driver is probed from DT only and therefore
> .probe() will only be called if there's a matching entry in the OF
> device ID table. match can never be NULL.

Ah, ok that would make sense.

Cheers Jon
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pinctrl/pinctrl-tegra-xusb.c b/drivers/pinctrl/pinctrl-tegra-xusb.c
index c61594066e26..0030cfb9c0a8 100644
--- a/drivers/pinctrl/pinctrl-tegra-xusb.c
+++ b/drivers/pinctrl/pinctrl-tegra-xusb.c
@@ -899,6 +899,9 @@  static int tegra_xusb_padctl_probe(struct platform_device *pdev)
 	padctl->dev = &pdev->dev;
 
 	match = of_match_node(tegra_xusb_padctl_of_match, pdev->dev.of_node);
+	if (!match)
+		return -EINVAL;
+
 	padctl->soc = match->data;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);