From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94072C2D0A3 for ; Thu, 29 Oct 2020 10:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4178520706 for ; Thu, 29 Oct 2020 10:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726430AbgJ2KIF (ORCPT ); Thu, 29 Oct 2020 06:08:05 -0400 Received: from foss.arm.com ([217.140.110.172]:58836 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725815AbgJ2KIE (ORCPT ); Thu, 29 Oct 2020 06:08:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0EC7B139F; Thu, 29 Oct 2020 03:08:04 -0700 (PDT) Received: from [10.57.54.223] (unknown [10.57.54.223]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 95AE73F66E; Thu, 29 Oct 2020 03:08:02 -0700 (PDT) Subject: Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate() To: Yu Kuai , joro@8bytes.org, heiko@sntech.de, jeffy.chen@rock-chips.com Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com References: <20201029092202.900218-1-yukuai3@huawei.com> From: Robin Murphy Message-ID: <98dec09e-08a1-6550-fa4e-85a8104b90e1@arm.com> Date: Thu, 29 Oct 2020 10:08:01 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20201029092202.900218-1-yukuai3@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-10-29 09:22, Yu Kuai wrote: > If of_find_device_by_node() failed in rk_iommu_of_xlate(), null pointer > dereference will be triggered. Thus return error code if > of_find_device_by_node() failed. How can that happen? (Given that ".suppress_bind_attrs = true") Robin. > Fixes: 5fd577c3eac3("iommu/rockchip: Use OF_IOMMU to attach devices automatically") > Signed-off-by: Yu Kuai > --- > drivers/iommu/rockchip-iommu.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c > index e5d86b7177de..090d149ef8e9 100644 > --- a/drivers/iommu/rockchip-iommu.c > +++ b/drivers/iommu/rockchip-iommu.c > @@ -1099,6 +1099,9 @@ static int rk_iommu_of_xlate(struct device *dev, > > iommu_dev = of_find_device_by_node(args->np); > > + if (!iommu_dev) > + return -ENODEV; > + > data->iommu = platform_get_drvdata(iommu_dev); > dev_iommu_priv_set(dev, data); > >