public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
Cc: <linux-kernel@vger.kernel.org>,
	<iommu@lists.linux-foundation.org>,
	jean-philippe@linaro.org, will@kernel.org,
	linuxarm@openeuler.org, prime.zeng@hisilicon.com
Subject: Re: [PATCH] iommu: Check dev->iommu in iommu_dev_xxx functions
Date: Tue, 26 Jan 2021 13:50:40 +0000	[thread overview]
Message-ID: <20210126135039.000039a0@arm.com> (raw)
In-Reply-To: <20210126130629.8928-1-shameerali.kolothum.thodi@huawei.com>

On Tue, 26 Jan 2021 13:06:29 +0000
Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> wrote:

> The device iommu probe/attach might have failed leaving dev->iommu
> to NULL and device drivers may still invoke these functions resulting
> a crash in iommu vendor driver code. Hence make sure we check that.
> 
> Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
> ---
>  drivers/iommu/iommu.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index ffeebda8d6de..cb68153c5cc0 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -2867,7 +2867,7 @@ bool iommu_dev_has_feature(struct device *dev,
> enum iommu_dev_features feat) {
>  	const struct iommu_ops *ops = dev->bus->iommu_ops;
>  
> -	if (ops && ops->dev_has_feat)
> +	if (dev->iommu && ops && ops->dev_has_feat)
>  		return ops->dev_has_feat(dev, feat);

Might make sense to make these more self-contained, e.g.:

	if (dev->iommu && dev->iommu->ops->foo)
		dev->iommu->ops->foo()

Robin.

 
>  	return false;
> @@ -2878,7 +2878,7 @@ int iommu_dev_enable_feature(struct device
> *dev, enum iommu_dev_features feat) {
>  	const struct iommu_ops *ops = dev->bus->iommu_ops;
>  
> -	if (ops && ops->dev_enable_feat)
> +	if (dev->iommu && ops && ops->dev_enable_feat)
>  		return ops->dev_enable_feat(dev, feat);
>  
>  	return -ENODEV;
> @@ -2894,7 +2894,7 @@ int iommu_dev_disable_feature(struct device
> *dev, enum iommu_dev_features feat) {
>  	const struct iommu_ops *ops = dev->bus->iommu_ops;
>  
> -	if (ops && ops->dev_disable_feat)
> +	if (dev->iommu && ops && ops->dev_disable_feat)
>  		return ops->dev_disable_feat(dev, feat);
>  
>  	return -EBUSY;
> @@ -2905,7 +2905,7 @@ bool iommu_dev_feature_enabled(struct device
> *dev, enum iommu_dev_features feat) {
>  	const struct iommu_ops *ops = dev->bus->iommu_ops;
>  
> -	if (ops && ops->dev_feat_enabled)
> +	if (dev->iommu && ops && ops->dev_feat_enabled)
>  		return ops->dev_feat_enabled(dev, feat);
>  
>  	return false;


  reply	other threads:[~2021-01-26 13:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 13:06 [PATCH] iommu: Check dev->iommu in iommu_dev_xxx functions Shameer Kolothum
2021-01-26 13:50 ` Robin Murphy [this message]
2021-01-26 16:40   ` Shameerali Kolothum Thodi
2021-01-26 17:24     ` Robin Murphy
2021-01-28 12:54 ` Joerg Roedel

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=20210126135039.000039a0@arm.com \
    --to=robin.murphy@arm.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jean-philippe@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@openeuler.org \
    --cc=prime.zeng@hisilicon.com \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=will@kernel.org \
    /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