Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5344159imu; Wed, 19 Dec 2018 09:29:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/V6hr/xyddzTGtBfI3AoRNTuEdk97IzcIbHYCaXiya6nVLKKeyMNjNgBf5QvQrt1aM73oMI X-Received: by 2002:a17:902:2468:: with SMTP id m37mr21081473plg.314.1545240567549; Wed, 19 Dec 2018 09:29:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545240567; cv=none; d=google.com; s=arc-20160816; b=ehq8vSexCZ1eJRNqfgENAiZTuoK5VWOuNcNwbYQ2ee0wxQVzuyHY9lI2IxxsjLr7L1 u+IbiyI/g9aY5G22PXhrGbSbzCT9/WjVtq6VuPwX5F9zvu/b/2qygUnzxqfVNdI2Vseo UMTs8StyndZJh0qZTNdqR/ax6BUhkDVnvA0PWMaVNn6sv3kPZVxtAgjORV661VJnSbjN jYIfuqzIXMlDfmJrQIzxm31mD/h/8J5Qr7hpOpB5WpRDfFbFOd/zNLHunSlKMnKrhEec q66uB1uo3mMoM2+1le1IUZDZYhNl6aofQMBQJvT7szaIQyVgwHZyLyZg029aTOUmG9Dk SoRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=VbDUoRFB6noilF43afEqK4wmrD9U8CSjsXnnpEK3Odo=; b=TbMK/ktlcgFlsMyV31GANILew3o4FiUhn7Rv6ah6iozNdbCOi9Ix8OZYX7q7ZsKD6H zLI7ri+VlGxA1ZDGI+RJ8BRqNNCwsl2ERXKIqHyjAh/kn+3j5E9vGmM7VYaPjnP+KpNU W09hlEdt1h6uztJm87ZYtAD+GYTUN/aEABS+Jx1UYQJyAKsc3OvuiulcXGlEOMzaw9g9 xUQgm0oXS65Jyzptkj5QhtV6FTMaGm6/eH+4FQFFpTMow4yXQ5L7uwgZ9OQPbl88C1QO bVwIalNgx8aQ+z63r9IglXX0qjhO5hqdPrfJJ70OjoDIbYWgHlbJPlKQBtg7NuLzwu0i qO4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15si16237993pgm.420.2018.12.19.09.29.08; Wed, 19 Dec 2018 09:29:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729572AbeLSOez (ORCPT + 99 others); Wed, 19 Dec 2018 09:34:55 -0500 Received: from 8bytes.org ([81.169.241.247]:54792 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbeLSOex (ORCPT ); Wed, 19 Dec 2018 09:34:53 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id D2CEB3F4; Wed, 19 Dec 2018 15:34:51 +0100 (CET) Date: Wed, 19 Dec 2018 15:34:51 +0100 From: Joerg Roedel To: Marek Szyprowski Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, jroedel@suse.de, Sudeep Holla , Robin Murphy , Krzysztof Kozlowski Subject: Re: [PATCH 3/4] iommu/of: Don't call iommu_ops->add_device directly Message-ID: <20181219143451.GY16835@8bytes.org> References: <20181211150513.15161-1-joro@8bytes.org> <20181211150513.15161-4-joro@8bytes.org> <30d86186-e0a2-2be1-2295-20510fbd74ba@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <30d86186-e0a2-2be1-2295-20510fbd74ba@samsung.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marek, thanks for the report! On Wed, Dec 19, 2018 at 10:54:18AM +0100, Marek Szyprowski wrote: > On 2018-12-11 16:05, Joerg Roedel wrote: > > From: Joerg Roedel > > > > Make sure to invoke this call-back through the proper > > function of the IOMMU-API. > > > > Signed-off-by: Joerg Roedel > > --- > > drivers/iommu/of_iommu.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c > > index c5dd63072529..4d4847de727e 100644 > > --- a/drivers/iommu/of_iommu.c > > +++ b/drivers/iommu/of_iommu.c > > @@ -218,10 +218,10 @@ const struct iommu_ops *of_iommu_configure(struct device *dev, > > ops = dev->iommu_fwspec->ops; > > /* > > * If we have reason to believe the IOMMU driver missed the initial > > - * add_device callback for dev, replay it to get things in order. > > + * probe for dev, replay it to get things in order. > > */ > > - if (ops && ops->add_device && dev->bus && !dev->iommu_group) > > - err = ops->add_device(dev); > > + if (dev->bus && !dev->iommu_group) > > + err = iommu_probe_device(dev); > > This change removes a check for NULL ops, what causes NULL pointer > exception on first device without IOMMU. Bummer, this check was supposed to be in iommu_probe_device(), but apparently it got lost. Does the attached patch fix it? > I'm also not sure if this is a good idea to call iommu_probe_device(), > which comes from dev->bus->iommu_ops, which might be different from ops > from local variable. The local variable comes from dev->iommu_fwspec->ops, which should be exactly the same as dev->bus->iommu_ops. I'll leave that for now until it turns out to be a problem (which I don't expect). Regards, Joerg diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index a2131751dcff..3ed4db334341 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -114,10 +114,14 @@ void iommu_device_unregister(struct iommu_device *iommu) int iommu_probe_device(struct device *dev) { const struct iommu_ops *ops = dev->bus->iommu_ops; + int ret = -EINVAL; WARN_ON(dev->iommu_group); - return ops->add_device(dev); + if (ops) + ret = ops->add_device(dev); + + return ret; } void iommu_release_device(struct device *dev)