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=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 924C4C4363A for ; Thu, 29 Oct 2020 13:51:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B35E21D47 for ; Thu, 29 Oct 2020 13:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727697AbgJ2Nv1 (ORCPT ); Thu, 29 Oct 2020 09:51:27 -0400 Received: from foss.arm.com ([217.140.110.172]:37804 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgJ2Nv0 (ORCPT ); Thu, 29 Oct 2020 09:51:26 -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 ED001139F; Thu, 29 Oct 2020 06:51:25 -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 9BDDC3F719; Thu, 29 Oct 2020 06:51:24 -0700 (PDT) Subject: Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate() To: "yukuai (C)" , 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> <98dec09e-08a1-6550-fa4e-85a8104b90e1@arm.com> <35ff5111-1270-fc88-788c-4fb9e38faa85@huawei.com> From: Robin Murphy Message-ID: Date: Thu, 29 Oct 2020 13:51:23 +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: <35ff5111-1270-fc88-788c-4fb9e38faa85@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 13:19, yukuai (C) wrote: > > On 2020/10/29 18:08, Robin Murphy wrote: >> 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. > > I'm not sure if that could happen... > > My thought is that it's better to do such checking to aviod any possible > problem. ->of_xlate() is only invoked on the specific set of ops returned by iommu_ops_from_fwnode(). In turn, iommu_ops_from_fwnode() will only return those ops if the driver has successfully probed and called iommu_register_device() with the relevant DT node. For the driver to have been able to probe at all, a platform device associated with that DT node must have been created, and therefore of_find_device_by_node() cannot fail. If there ever were some problem serious enough to break that fundamental assumption, then I *want* these drivers to crash right here, with a nice clear stack trace to start debugging from. So no, I firmly disagree that adding redundant code, which will never do anything except attempt to paper over catastrophic memory corruption, is "better". Sorry :) Robin.