From nobody Mon Feb 9 10:24:31 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93D13EB64DD for ; Thu, 27 Jul 2023 05:52:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232470AbjG0FwN (ORCPT ); Thu, 27 Jul 2023 01:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjG0Fvv (ORCPT ); Thu, 27 Jul 2023 01:51:51 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99A5530F3; Wed, 26 Jul 2023 22:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690437086; x=1721973086; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rapigetQWIYey116Fahotdb3UUfJeYnWhEFac994Gac=; b=Yy/VTgVEncOuV0XJh2UlBNkcNhnKRBO5hENnPQoH1AH5RiKzsdQt+WNV v70xz/LaQQoRYALRDI5MhzxHTC2P55SzF+FQrQLKZ65pzr1BrTJ0VydmT eUIX818Ke53S2K/3NcM0SjUQ/reVJWFtO7XBNnEWqMc32BtmLB9q3Wokk W1zElZCRAqHi55JudSPHDlYxbiTFISzLjYdXCiSaG5GRF2siJZsdaPnW3 yytCpU3H16MjKENQuOj+Z9V4s+wYJQflDSFg+FOMfvdDvqPwM8dFpSDjQ emtTy0SUxrPS3wb9FU0OG7t/a7wgypThNKi1vyvRDiLRFZhm7xKbNrrXa Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="399152537" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="399152537" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2023 22:51:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10783"; a="840585289" X-IronPort-AV: E=Sophos;i="6.01,234,1684825200"; d="scan'208";a="840585289" Received: from allen-box.sh.intel.com ([10.239.159.127]) by fmsmga002.fm.intel.com with ESMTP; 26 Jul 2023 22:51:02 -0700 From: Lu Baolu To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Jean-Philippe Brucker , Nicolin Chen Cc: Yi Liu , Jacob Pan , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v2 05/12] iommu: Change the return value of dev_iommu_get() Date: Thu, 27 Jul 2023 13:48:30 +0800 Message-Id: <20230727054837.147050-6-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230727054837.147050-1-baolu.lu@linux.intel.com> References: <20230727054837.147050-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Make dev_iommu_get() return 0 for success and error numbers for failure. This will make the code neat and readable. No functionality changes. Reviewed-by: Jacob Pan Signed-off-by: Lu Baolu --- drivers/iommu/iommu.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 00309f66153b..4ba3bb692993 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -290,20 +290,20 @@ void iommu_device_unregister(struct iommu_device *iom= mu) } EXPORT_SYMBOL_GPL(iommu_device_unregister); =20 -static struct dev_iommu *dev_iommu_get(struct device *dev) +static int dev_iommu_get(struct device *dev) { struct dev_iommu *param =3D dev->iommu; =20 if (param) - return param; + return 0; =20 param =3D kzalloc(sizeof(*param), GFP_KERNEL); if (!param) - return NULL; + return -ENOMEM; =20 mutex_init(¶m->lock); dev->iommu =3D param; - return param; + return 0; } =20 static void dev_iommu_free(struct device *dev) @@ -346,8 +346,9 @@ static int iommu_init_device(struct device *dev, const = struct iommu_ops *ops) struct iommu_group *group; int ret; =20 - if (!dev_iommu_get(dev)) - return -ENOMEM; + ret =3D dev_iommu_get(dev); + if (ret) + return ret; =20 if (!try_module_get(ops->owner)) { ret =3D -EINVAL; @@ -2743,12 +2744,14 @@ int iommu_fwspec_init(struct device *dev, struct fw= node_handle *iommu_fwnode, const struct iommu_ops *ops) { struct iommu_fwspec *fwspec =3D dev_iommu_fwspec_get(dev); + int ret; =20 if (fwspec) return ops =3D=3D fwspec->ops ? 0 : -EINVAL; =20 - if (!dev_iommu_get(dev)) - return -ENOMEM; + ret =3D dev_iommu_get(dev); + if (ret) + return ret; =20 /* Preallocate for the overwhelmingly common case of 1 ID */ fwspec =3D kzalloc(struct_size(fwspec, ids, 1), GFP_KERNEL); --=20 2.34.1