diff mbox series

iommu/qcom: add missing put_device() call in qcom_iommu_of_xlate()

Message ID 20200918011357.909335-1-yukuai3@huawei.com (mailing list archive)
State New, archived
Headers show
Series iommu/qcom: add missing put_device() call in qcom_iommu_of_xlate() | expand

Commit Message

Yu Kuai Sept. 18, 2020, 1:13 a.m. UTC
if of_find_device_by_node() succeed, qcom_iommu_of_xlate() doesn't have
a corresponding put_device(). Thus add put_device() to fix the exception
handling for this function implementation.

Fixes: e86d1aa8b60f ("iommu/arm-smmu: Move Arm SMMU drivers into their own subdirectory")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 drivers/iommu/arm/arm-smmu/qcom_iommu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Will Deacon Sept. 21, 2020, 5:50 p.m. UTC | #1
On Fri, Sep 18, 2020 at 09:13:57AM +0800, Yu Kuai wrote:
> if of_find_device_by_node() succeed, qcom_iommu_of_xlate() doesn't have
> a corresponding put_device(). Thus add put_device() to fix the exception
> handling for this function implementation.
> 
> Fixes: e86d1aa8b60f ("iommu/arm-smmu: Move Arm SMMU drivers into their own subdirectory")

That's probably not accurate, in that this driver used to live under
drivers/iommu/ and assumedly had this bug there as well.

> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  drivers/iommu/arm/arm-smmu/qcom_iommu.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

I guess Rob will pick this up.

Will
Rob Clark Sept. 21, 2020, 6:27 p.m. UTC | #2
On Mon, Sep 21, 2020 at 10:50 AM Will Deacon <will@kernel.org> wrote:
>
> On Fri, Sep 18, 2020 at 09:13:57AM +0800, Yu Kuai wrote:
> > if of_find_device_by_node() succeed, qcom_iommu_of_xlate() doesn't have
> > a corresponding put_device(). Thus add put_device() to fix the exception
> > handling for this function implementation.
> >
> > Fixes: e86d1aa8b60f ("iommu/arm-smmu: Move Arm SMMU drivers into their own subdirectory")
>
> That's probably not accurate, in that this driver used to live under
> drivers/iommu/ and assumedly had this bug there as well.
>
> > Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> > ---
> >  drivers/iommu/arm/arm-smmu/qcom_iommu.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
>
> I guess Rob will pick this up.

Probably overkill for me to send a pull req for a single patch, if you
want to pick it up:

Acked-by: Rob Clark <robdclark@gmail.com>
Rob Clark Sept. 21, 2020, 6:33 p.m. UTC | #3
On Mon, Sep 21, 2020 at 11:27 AM Rob Clark <robdclark@gmail.com> wrote:
>
> On Mon, Sep 21, 2020 at 10:50 AM Will Deacon <will@kernel.org> wrote:
> >
> > On Fri, Sep 18, 2020 at 09:13:57AM +0800, Yu Kuai wrote:
> > > if of_find_device_by_node() succeed, qcom_iommu_of_xlate() doesn't have
> > > a corresponding put_device(). Thus add put_device() to fix the exception
> > > handling for this function implementation.
> > >
> > > Fixes: e86d1aa8b60f ("iommu/arm-smmu: Move Arm SMMU drivers into their own subdirectory")
> >
> > That's probably not accurate, in that this driver used to live under
> > drivers/iommu/ and assumedly had this bug there as well.
> >

and fwiw, that looks like it should be:

Fixes: 0ae349a0f33fb ("iommu/qcom: Add qcom_iommu")

> > > Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> > > ---
> > >  drivers/iommu/arm/arm-smmu/qcom_iommu.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > I guess Rob will pick this up.
>
> Probably overkill for me to send a pull req for a single patch, if you
> want to pick it up:
>
> Acked-by: Rob Clark <robdclark@gmail.com>
kernel test robot Sept. 21, 2020, 7:13 p.m. UTC | #4
Hi Yu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on iommu/next]
[also build test WARNING on linus/master v5.9-rc6 next-20200921]
[cannot apply to robclark/msm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
config: arm64-randconfig-r023-20200920 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4e8c028158b56d9c2142a62464e8e0686bde3584)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm64 cross compiling tool for clang build
        # apt-get install binutils-aarch64-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/iommu/arm/arm-smmu/qcom_iommu.c:601:4: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation]
                           return -EINVAL;
                           ^
   drivers/iommu/arm/arm-smmu/qcom_iommu.c:599:3: note: previous statement is here
                   if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
                   ^
   1 warning generated.

# https://github.com/0day-ci/linux/commit/2d982fb40897ad8088dd9dba06aee499f51c73ba
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
git checkout 2d982fb40897ad8088dd9dba06aee499f51c73ba
vim +/if +601 drivers/iommu/arm/arm-smmu/qcom_iommu.c

0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  562  
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  563  static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  564  {
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  565  	struct qcom_iommu_dev *qcom_iommu;
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  566  	struct platform_device *iommu_pdev;
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  567  	unsigned asid = args->args[0];
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  568  
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  569  	if (args->args_count != 1) {
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  570  		dev_err(dev, "incorrect number of iommu params found for %s "
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  571  			"(found %d, expected 1)\n",
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  572  			args->np->full_name, args->args_count);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  573  		return -EINVAL;
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  574  	}
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  575  
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  576  	iommu_pdev = of_find_device_by_node(args->np);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  577  	if (WARN_ON(!iommu_pdev))
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  578  		return -EINVAL;
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  579  
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  580  	qcom_iommu = platform_get_drvdata(iommu_pdev);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  581  
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  582  	/* make sure the asid specified in dt is valid, so we don't have
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  583  	 * to sanity check this elsewhere, since 'asid - 1' is used to
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  584  	 * index into qcom_iommu->ctxs:
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  585  	 */
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  586  	if (WARN_ON(asid < 1) ||
2d982fb40897ad drivers/iommu/arm/arm-smmu/qcom_iommu.c Yu Kuai      2020-09-18  587  	    WARN_ON(asid > qcom_iommu->num_ctxs)) {
2d982fb40897ad drivers/iommu/arm/arm-smmu/qcom_iommu.c Yu Kuai      2020-09-18  588  		put_device(&iommu_pdev->dev);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  589  		return -EINVAL;
2d982fb40897ad drivers/iommu/arm/arm-smmu/qcom_iommu.c Yu Kuai      2020-09-18  590  	}
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  591  
09b5dfff9ad68f drivers/iommu/qcom_iommu.c              Joerg Roedel 2020-03-26  592  	if (!dev_iommu_priv_get(dev)) {
09b5dfff9ad68f drivers/iommu/qcom_iommu.c              Joerg Roedel 2020-03-26  593  		dev_iommu_priv_set(dev, qcom_iommu);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  594  	} else {
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  595  		/* make sure devices iommus dt node isn't referring to
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  596  		 * multiple different iommu devices.  Multiple context
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  597  		 * banks are ok, but multiple devices are not:
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  598  		 */
09b5dfff9ad68f drivers/iommu/qcom_iommu.c              Joerg Roedel 2020-03-26  599  		if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
2d982fb40897ad drivers/iommu/arm/arm-smmu/qcom_iommu.c Yu Kuai      2020-09-18  600  			put_device(&iommu_pdev->dev);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09 @601  			return -EINVAL;
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  602  	}
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  603  
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  604  	return iommu_fwspec_add_ids(dev, &asid, 1);
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  605  }
0ae349a0f33fb0 drivers/iommu/qcom_iommu.c              Rob Clark    2017-08-09  606  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Will Deacon Sept. 21, 2020, 8:45 p.m. UTC | #5
On Tue, Sep 22, 2020 at 03:13:53AM +0800, kernel test robot wrote:
> Thank you for the patch! Perhaps something to improve:
> 
> [auto build test WARNING on iommu/next]
> [also build test WARNING on linus/master v5.9-rc6 next-20200921]
> [cannot apply to robclark/msm-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
> config: arm64-randconfig-r023-20200920 (attached as .config)
> compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4e8c028158b56d9c2142a62464e8e0686bde3584)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install arm64 cross compiling tool for clang build
>         # apt-get install binutils-aarch64-linux-gnu
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
> >> drivers/iommu/arm/arm-smmu/qcom_iommu.c:601:4: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation]
>                            return -EINVAL;
>                            ^
>    drivers/iommu/arm/arm-smmu/qcom_iommu.c:599:3: note: previous statement is here
>                    if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))

Oh, this looks like a nasty bug. Seems we're missing some braces.

Will
kernel test robot Sept. 23, 2020, 4:32 a.m. UTC | #6
Hi Yu,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on iommu/next]
[also build test WARNING on linus/master v5.9-rc6 next-20200922]
[cannot apply to robclark/msm-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
config: arm64-randconfig-m031-20200923 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from arch/arm64/include/asm/atomic.h:12,
                    from include/linux/atomic.h:7,
                    from drivers/iommu/arm/arm-smmu/qcom_iommu.c:9:
   drivers/iommu/arm/arm-smmu/qcom_iommu.c: In function 'qcom_iommu_of_xlate':
>> include/linux/compiler.h:56:23: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
      56 | #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
         |                       ^~
   drivers/iommu/arm/arm-smmu/qcom_iommu.c:599:3: note: in expansion of macro 'if'
     599 |   if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
         |   ^~
   drivers/iommu/arm/arm-smmu/qcom_iommu.c:601:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     601 |    return -EINVAL;
         |    ^~~~~~

# https://github.com/0day-ci/linux/commit/2d982fb40897ad8088dd9dba06aee499f51c73ba
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
git checkout 2d982fb40897ad8088dd9dba06aee499f51c73ba
vim +/if +56 include/linux/compiler.h

2bcd521a684cc9 Steven Rostedt 2008-11-21  50  
2bcd521a684cc9 Steven Rostedt 2008-11-21  51  #ifdef CONFIG_PROFILE_ALL_BRANCHES
2bcd521a684cc9 Steven Rostedt 2008-11-21  52  /*
2bcd521a684cc9 Steven Rostedt 2008-11-21  53   * "Define 'is'", Bill Clinton
2bcd521a684cc9 Steven Rostedt 2008-11-21  54   * "Define 'if'", Steven Rostedt
2bcd521a684cc9 Steven Rostedt 2008-11-21  55   */
a15fd609ad53a6 Linus Torvalds 2019-03-20 @56  #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
a15fd609ad53a6 Linus Torvalds 2019-03-20  57  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Will Deacon Sept. 28, 2020, 11:08 p.m. UTC | #7
On Mon, Sep 21, 2020 at 09:45:57PM +0100, Will Deacon wrote:
> On Tue, Sep 22, 2020 at 03:13:53AM +0800, kernel test robot wrote:
> > Thank you for the patch! Perhaps something to improve:
> > 
> > [auto build test WARNING on iommu/next]
> > [also build test WARNING on linus/master v5.9-rc6 next-20200921]
> > [cannot apply to robclark/msm-next]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch]
> > 
> > url:    https://github.com/0day-ci/linux/commits/Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
> > config: arm64-randconfig-r023-20200920 (attached as .config)
> > compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4e8c028158b56d9c2142a62464e8e0686bde3584)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install arm64 cross compiling tool for clang build
> >         # apt-get install binutils-aarch64-linux-gnu
> >         # save the attached .config to linux build tree
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64 
> > 
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > All warnings (new ones prefixed by >>):
> > 
> > >> drivers/iommu/arm/arm-smmu/qcom_iommu.c:601:4: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation]
> >                            return -EINVAL;
> >                            ^
> >    drivers/iommu/arm/arm-smmu/qcom_iommu.c:599:3: note: previous statement is here
> >                    if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
> 
> Oh, this looks like a nasty bug. Seems we're missing some braces.

Yu Kuai: please could you send a v2 of this?

Will
Yu Kuai Sept. 29, 2020, 1:37 a.m. UTC | #8
On 2020/09/29 7:08, Will Deacon wrote:
> On Mon, Sep 21, 2020 at 09:45:57PM +0100, Will Deacon wrote:
>> On Tue, Sep 22, 2020 at 03:13:53AM +0800, kernel test robot wrote:
>>> Thank you for the patch! Perhaps something to improve:
>>>
>>> [auto build test WARNING on iommu/next]
>>> [also build test WARNING on linus/master v5.9-rc6 next-20200921]
>>> [cannot apply to robclark/msm-next]
>>> [If your patch is applied to the wrong git tree, kindly drop us a note.
>>> And when submitting patch, we suggest to use '--base' as documented in
>>> https://git-scm.com/docs/git-format-patch]
>>>
>>> url:    https://github.com/0day-ci/linux/commits/Yu-Kuai/iommu-qcom-add-missing-put_device-call-in-qcom_iommu_of_xlate/20200918-091341
>>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git next
>>> config: arm64-randconfig-r023-20200920 (attached as .config)
>>> compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 4e8c028158b56d9c2142a62464e8e0686bde3584)
>>> reproduce (this is a W=1 build):
>>>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>>>          chmod +x ~/bin/make.cross
>>>          # install arm64 cross compiling tool for clang build
>>>          # apt-get install binutils-aarch64-linux-gnu
>>>          # save the attached .config to linux build tree
>>>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
>>>
>>> If you fix the issue, kindly add following tag as appropriate
>>> Reported-by: kernel test robot <lkp@intel.com>
>>>
>>> All warnings (new ones prefixed by >>):
>>>
>>>>> drivers/iommu/arm/arm-smmu/qcom_iommu.c:601:4: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation]
>>>                             return -EINVAL;
>>>                             ^
>>>     drivers/iommu/arm/arm-smmu/qcom_iommu.c:599:3: note: previous statement is here
>>>                     if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
>>
>> Oh, this looks like a nasty bug. Seems we're missing some braces.
> 
> Yu Kuai: please could you send a v2 of this?
> 

Hi, Will

Thanks for your notice, will send a V2 soon.

Yu Kuai
diff mbox series

Patch

diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
index 9535a6af7553..7a9594d221e0 100644
--- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c
+++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c
@@ -584,8 +584,10 @@  static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 	 * index into qcom_iommu->ctxs:
 	 */
 	if (WARN_ON(asid < 1) ||
-	    WARN_ON(asid > qcom_iommu->num_ctxs))
+	    WARN_ON(asid > qcom_iommu->num_ctxs)) {
+		put_device(&iommu_pdev->dev);
 		return -EINVAL;
+	}
 
 	if (!dev_iommu_priv_get(dev)) {
 		dev_iommu_priv_set(dev, qcom_iommu);
@@ -595,6 +597,7 @@  static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
 		 * banks are ok, but multiple devices are not:
 		 */
 		if (WARN_ON(qcom_iommu != dev_iommu_priv_get(dev)))
+			put_device(&iommu_pdev->dev);
 			return -EINVAL;
 	}