iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu: rockchip: fix building without CONFIG_OF
@ 2018-04-04 10:23 Arnd Bergmann
       [not found] ` <20180404102401.3634085-1-arnd-r2nGTMty4D4@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2018-04-04 10:23 UTC (permalink / raw)
  To: Joerg Roedel, Heiko Stuebner
  Cc: Simon Xue, Arnd Bergmann, Marc Zyngier, Jeffy Chen,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Tomasz Figa,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Robin Murphy,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

We get a build error when compiling the iommu driver without CONFIG_OF:

drivers/iommu/rockchip-iommu.c: In function 'rk_iommu_of_xlate':
drivers/iommu/rockchip-iommu.c:1101:2: error: implicit declaration of function 'of_dev_put'; did you mean 'of_node_put'? [-Werror=implicit-function-declaration]

This replaces the of_dev_put() with the equivalent platform_device_put(),
and adds an error check for of_find_device_by_node() returning NULL,
which seems to be appropriate here given that we pass the device into
platform_get_drvdata() next, and that of_find_device_by_node() might
theoretically return a NULL pointer.

Fixes: 5fd577c3eac3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
---
This warning appears to only have been introduced in linux-next after
the merge window opened.
---
 drivers/iommu/rockchip-iommu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 5fc8656c60f9..fe9c9cc1a9d4 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1094,11 +1094,15 @@ static int rk_iommu_of_xlate(struct device *dev,
 		return -ENOMEM;
 
 	iommu_dev = of_find_device_by_node(args->np);
+	if (!iommu_dev) {
+		kfree(data);
+		return -ENODEV;
+	}
 
 	data->iommu = platform_get_drvdata(iommu_dev);
 	dev->archdata.iommu = data;
 
-	of_dev_put(iommu_dev);
+	platform_device_put(iommu_dev);
 
 	return 0;
 }
-- 
2.9.0

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

* Re: [PATCH] iommu: rockchip: fix building without CONFIG_OF
       [not found] ` <20180404102401.3634085-1-arnd-r2nGTMty4D4@public.gmane.org>
@ 2018-04-04 11:04   ` JeffyChen
  2018-04-04 11:12   ` Robin Murphy
  2018-05-03 12:46   ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: JeffyChen @ 2018-04-04 11:04 UTC (permalink / raw)
  To: Arnd Bergmann, Joerg Roedel, Heiko Stuebner
  Cc: Marc Zyngier, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi Amd,

Thanks for your patch.

On 04/04/2018 06:23 PM, Arnd Bergmann wrote:
> We get a build error when compiling the iommu driver without CONFIG_OF:
>
> drivers/iommu/rockchip-iommu.c: In function 'rk_iommu_of_xlate':
> drivers/iommu/rockchip-iommu.c:1101:2: error: implicit declaration of function 'of_dev_put'; did you mean 'of_node_put'? [-Werror=implicit-function-declaration]
>
oops, didn't notice that.

and checking other iommu drivers which call of_find_device_by_node() 
too, seems they didn't put() it? maybe we should fix them too

> This replaces the of_dev_put() with the equivalent platform_device_put(),
> and adds an error check for of_find_device_by_node() returning NULL,
> which seems to be appropriate here given that we pass the device into
> platform_get_drvdata() next, and that of_find_device_by_node() might
> theoretically return a NULL pointer.
hmm, i thought the of_iommu_xlate() checked that before calling us:


static int of_iommu_xlate(struct device *dev,
               struct of_phandle_args *iommu_spec)
{
...
     if ((ops && !ops->of_xlate) ||
         !of_device_is_available(iommu_spec->np) ||
         (!ops && !of_iommu_driver_present(iommu_spec->np)))
         return NO_IOMMU;
...
     return ops->of_xlate(dev, iommu_spec);


but it's better to check it ourself :)


>
> Fixes: 5fd577c3eac3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
> Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
> ---
> This warning appears to only have been introduced in linux-next after
> the merge window opened.
> ---
>   drivers/iommu/rockchip-iommu.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> index 5fc8656c60f9..fe9c9cc1a9d4 100644
> --- a/drivers/iommu/rockchip-iommu.c
> +++ b/drivers/iommu/rockchip-iommu.c
> @@ -1094,11 +1094,15 @@ static int rk_iommu_of_xlate(struct device *dev,
>   		return -ENOMEM;
>
>   	iommu_dev = of_find_device_by_node(args->np);
> +	if (!iommu_dev) {
> +		kfree(data);
> +		return -ENODEV;
> +	}
>
>   	data->iommu = platform_get_drvdata(iommu_dev);
>   	dev->archdata.iommu = data;
>
> -	of_dev_put(iommu_dev);
> +	platform_device_put(iommu_dev);
>
>   	return 0;
>   }
>

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

* Re: [PATCH] iommu: rockchip: fix building without CONFIG_OF
       [not found] ` <20180404102401.3634085-1-arnd-r2nGTMty4D4@public.gmane.org>
  2018-04-04 11:04   ` JeffyChen
@ 2018-04-04 11:12   ` Robin Murphy
  2018-05-03 12:46   ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Robin Murphy @ 2018-04-04 11:12 UTC (permalink / raw)
  To: Arnd Bergmann, Joerg Roedel, Heiko Stuebner
  Cc: Marc Zyngier, Jeffy Chen, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi Arnd,

On 04/04/18 11:23, Arnd Bergmann wrote:
> We get a build error when compiling the iommu driver without CONFIG_OF:
> 
> drivers/iommu/rockchip-iommu.c: In function 'rk_iommu_of_xlate':
> drivers/iommu/rockchip-iommu.c:1101:2: error: implicit declaration of function 'of_dev_put'; did you mean 'of_node_put'? [-Werror=implicit-function-declaration]
> 
> This replaces the of_dev_put() with the equivalent platform_device_put(),
> and adds an error check for of_find_device_by_node() returning NULL,
> which seems to be appropriate here given that we pass the device into
> platform_get_drvdata() next, and that of_find_device_by_node() might
> theoretically return a NULL pointer.
> 
> Fixes: 5fd577c3eac3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
> Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
> ---
> This warning appears to only have been introduced in linux-next after
> the merge window opened.
> ---
>   drivers/iommu/rockchip-iommu.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> index 5fc8656c60f9..fe9c9cc1a9d4 100644
> --- a/drivers/iommu/rockchip-iommu.c
> +++ b/drivers/iommu/rockchip-iommu.c
> @@ -1094,11 +1094,15 @@ static int rk_iommu_of_xlate(struct device *dev,
>   		return -ENOMEM;
>   
>   	iommu_dev = of_find_device_by_node(args->np);
> +	if (!iommu_dev) {

Actually, though the logic is perhaps a bit subtle, this cannot 
reasonably happen - .of_xlate is only called via a set of iommu_ops 
associated with the IOMMU node (args->np here); those ops are only 
registered for the given node at the end of rk_iommu_probe(), by which 
point the IOMMU device exists and is otherwise successfully probed, so 
the platform bus lookup should never be able to fail.

> +		kfree(data);
> +		return -ENODEV;
> +	}
>   
>   	data->iommu = platform_get_drvdata(iommu_dev);
>   	dev->archdata.iommu = data;
>   
> -	of_dev_put(iommu_dev);
> +	platform_device_put(iommu_dev);

This bit looks reasonable, thanks for the fix.

Robin.

>   
>   	return 0;
>   }
> 

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

* Re: [PATCH] iommu: rockchip: fix building without CONFIG_OF
       [not found] ` <20180404102401.3634085-1-arnd-r2nGTMty4D4@public.gmane.org>
  2018-04-04 11:04   ` JeffyChen
  2018-04-04 11:12   ` Robin Murphy
@ 2018-05-03 12:46   ` Joerg Roedel
  2 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2018-05-03 12:46 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Marc Zyngier, Jeffy Chen, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	Heiko Stuebner

On Wed, Apr 04, 2018 at 12:23:53PM +0200, Arnd Bergmann wrote:
> We get a build error when compiling the iommu driver without CONFIG_OF:
> 
> drivers/iommu/rockchip-iommu.c: In function 'rk_iommu_of_xlate':
> drivers/iommu/rockchip-iommu.c:1101:2: error: implicit declaration of function 'of_dev_put'; did you mean 'of_node_put'? [-Werror=implicit-function-declaration]
> 
> This replaces the of_dev_put() with the equivalent platform_device_put(),
> and adds an error check for of_find_device_by_node() returning NULL,
> which seems to be appropriate here given that we pass the device into
> platform_get_drvdata() next, and that of_find_device_by_node() might
> theoretically return a NULL pointer.
> 
> Fixes: 5fd577c3eac3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically")
> Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
> ---
> This warning appears to only have been introduced in linux-next after
> the merge window opened.
> ---
>  drivers/iommu/rockchip-iommu.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Changed patch according to Robins comments and applied it, thanks.

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

end of thread, other threads:[~2018-05-03 12:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04 10:23 [PATCH] iommu: rockchip: fix building without CONFIG_OF Arnd Bergmann
     [not found] ` <20180404102401.3634085-1-arnd-r2nGTMty4D4@public.gmane.org>
2018-04-04 11:04   ` JeffyChen
2018-04-04 11:12   ` Robin Murphy
2018-05-03 12:46   ` Joerg Roedel

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