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 98834C2D0A3 for ; Fri, 30 Oct 2020 01:27:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38410206BE for ; Fri, 30 Oct 2020 01:27:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725961AbgJ3B1h (ORCPT ); Thu, 29 Oct 2020 21:27:37 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:6933 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725372AbgJ3B1g (ORCPT ); Thu, 29 Oct 2020 21:27:36 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CMl6b5hklz70G5; Fri, 30 Oct 2020 09:27:35 +0800 (CST) Received: from [10.174.179.62] (10.174.179.62) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 30 Oct 2020 09:27:23 +0800 Subject: Re: [PATCH] iommu/rockchip: check return value of of_find_device_by_node() in rk_iommu_of_xlate() To: Robin Murphy , , , CC: , , , , References: <20201029092202.900218-1-yukuai3@huawei.com> <98dec09e-08a1-6550-fa4e-85a8104b90e1@arm.com> <35ff5111-1270-fc88-788c-4fb9e38faa85@huawei.com> From: "yukuai (C)" Message-ID: Date: Fri, 30 Oct 2020 09:27:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.62] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/10/29 21:51, Robin Murphy wrote: > 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 :) > Sounds reasonable, thanks for your explanation Yu Kuai