Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1025734lqd; Thu, 25 Apr 2024 04:04:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhwU91+Zehd+sIiJDhU/uqV9d/AAz0PsjCamMCWgcDePGl+blt0MEf31JPKLmtunU8XKmkbylOa3EkxR5BbTFtnjURFW0iIl3YS6URHw== X-Google-Smtp-Source: AGHT+IGnwwieWRO42MnJLMpEer8Bomisw86Qg6tIx91vZbwWyyrnK/alDaj2xp3Cdfg6MyP6K418 X-Received: by 2002:a05:6a00:1989:b0:6ed:d47e:625d with SMTP id d9-20020a056a00198900b006edd47e625dmr5890395pfl.30.1714043076195; Thu, 25 Apr 2024 04:04:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714043076; cv=pass; d=google.com; s=arc-20160816; b=pBhnUAVgSdxxb9ANgz4t/aUmSWEwuJJPgpFWh7y9U8Xd9BUs6urxswsHXa+Nr1WOdY FX/iPfMlvGfQA3wwexHEtgRGCL/iKP3BsvbpH6uk/qTnWQ2tOvFbovCL7RyrFxPV+s93 f+3o2GxUNdpob/AqUYXKPpwCWSIopWbkwwf3gYqgY61pQh+LJ1j8MznH3Y0KO1Fmyr8N l8m7jx6vQFp1F5wM99x9GArknrGjMFRkD47XsyPceEF4dkXJMO8xryD/i8yHiiY2RBWu QCdEGMgSLMS3rc/0e6BbskPVH1UwBYCCBcmxirnTsN2eNYTzHXCKDuge4OZ2PuOUX76r PcyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=EI91U2foNCov18pMTroax3L5blThDM1Gptfmav0qff8=; fh=6duBR0Eq8GGYBfMHpKgDrkm91GKMCf7r6tQHlIzKgHc=; b=u9+tD72JPdmyvnHSx5TyqqHYWUiFHGnIDrYEZGYcDX4VzJ/gN7jCTYIZkjqBIeaA01 XEmxe2/sbzbG7ouJ3OLk6aZBLVzhnabesj29A/dJZT2JAcfAAz5MlKqQUqHSB1FkDWLv wfJisXnAfgwV+Oe1Lscv+H4PL6SwzAl6weE7HYqy0WtBf8PCM/C0G4BDFTCSJVzD7hjj Tz5i324YA9E1LRvHkndBLOTq43aywim10mlAdBxDw9YfeQo37LgSihLTQhaoKgKy4hRX XrtTeQtUKaCZFssnYaiJ+2ofEZLyuCNroGUEYI7FZuoGPJA72YCxG/n1klGw19wUAHHW 8OWw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-158400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id bm18-20020a056a00321200b006ee25444468si12851290pfb.279.2024.04.25.04.04.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 04:04:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-158400-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158400-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 04F79B2154A for ; Thu, 25 Apr 2024 10:36:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29A121DDC9; Thu, 25 Apr 2024 10:35:59 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4BC9F1CFA0 for ; Thu, 25 Apr 2024 10:35:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714041358; cv=none; b=oDKvrxqFRb/qhFQ4aFOQTWbmKizpFWdxH6zVao53Kx6TGLZYJBWclbPVK4SgK0LvJbpDPG435REkymJxSkDCQzPSYiplzJYaV/LVYfB5fm0csGvs2Ey1hMVC8bS05YP6O8pjf3z3Zx3iG3dCgw+dEPFDTRsPb3napcEQ11aAjcE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714041358; c=relaxed/simple; bh=q6lkpKJMorSwTo+NLAoNtokuFO5no9PMJ4oQa8UkFUs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Org/YYNvnAeXp4ZU7GARdNLqcbjgRVpGgbSjntr3aQjCAqvAaPyVM6lnLYsKc3iY+QiUWS+oJy2aHcsTTR8fP/hnWtbZZUEBbbIFCll4yHGyYQaTCtIEiUOLA4BZ6h8wqLqrz/b5xOsRrZaJEyfRpNNkBOiqwj8baRX5sUSutLI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C87EE1007; Thu, 25 Apr 2024 03:36:23 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 91E6E3F64C; Thu, 25 Apr 2024 03:35:54 -0700 (PDT) Message-ID: <473f2b61-9015-481a-b231-b642f6c7be41@arm.com> Date: Thu, 25 Apr 2024 11:35:53 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu/rockchip: Add missing check for of_find_device_by_node To: Chen Ni , joro@8bytes.org, will@kernel.org, heiko@sntech.de, jeffy.chen@rock-chips.com Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org References: <20240425091813.965003-1-nichen@iscas.ac.cn> From: Robin Murphy Content-Language: en-GB In-Reply-To: <20240425091813.965003-1-nichen@iscas.ac.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 25/04/2024 10:18 am, Chen Ni wrote: > Add check for the return value of of_find_device_by_node() and return > the error if it fails in order to avoid NULL pointer dereference. How would it return NULL? Or to put it another way, if a device has somehow vanished without unbinding its driver or unregistering the iommu_ops through which this is called, then the kernel state is clearly so broken that crashing is probably the safest thing to do. Furthermore if we couldn't assume we have the right device here then we also couldn't assume that its drvdata points to the right thing either, so we'd be rather stuck. Thanks, Robin. > Fixes: 5fd577c3eac3 ("iommu/rockchip: Use OF_IOMMU to attach devices automatically") > Signed-off-by: Chen Ni > --- > drivers/iommu/rockchip-iommu.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c > index 4b369419b32c..1225c1df6ef6 100644 > --- a/drivers/iommu/rockchip-iommu.c > +++ b/drivers/iommu/rockchip-iommu.c > @@ -1152,6 +1152,8 @@ static int rk_iommu_of_xlate(struct device *dev, > return -ENOMEM; > > iommu_dev = of_find_device_by_node(args->np); > + if (!iommu_dev) > + return -ENODEV; > > data->iommu = platform_get_drvdata(iommu_dev); > data->iommu->domain = &rk_identity_domain;