Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1988043rwb; Wed, 26 Jul 2023 23:44:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlGH/zjFU4wKSWO37RJaJNC1DWNDbGTvrKZA8vyD0EtUJBn5YtoJrmeUphiA4jA3/KPIOHEe X-Received: by 2002:a05:6870:3322:b0:1b7:89b5:7c11 with SMTP id x34-20020a056870332200b001b789b57c11mr2385655oae.9.1690440243500; Wed, 26 Jul 2023 23:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690440243; cv=none; d=google.com; s=arc-20160816; b=AvFYl8M/E+up413GhcuU4neaEhgnRBb9CeODvP/Ri2DFYWYxe1/psdWiYli2fKB5EC UPGDqDtilFG8H7OU9qYEdKl88SloLKLaFSCwDNRIj+tEXpkZ0v1oR7l9/oinGgihYFav jbofJ6Wg62hevSfFS4y73W2bXmEsGhC6HC1jox6YSK+TNknRkyKBmhGGunWLuv2VRhDs JID2WbeISpMijDUJwGyni/2b2ZqWF978mbz1lG8EEd7sDo3MN8N29qbjB+SGROGmqAKv jwuP1/jsGS9Ao/cLdPlZ0Q5tZ1mQfkgwFaB+ateHal9O6G8Jfdqi+N4qjZX8lPF2FF1/ 8QuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AUEgV+UUMOdXOCHO5AvpBxD4xzW8yH4FM3nZSDzD5gQ=; fh=5v0QJkujOnxKSzhmeWiMX/0q9X35NwMz+SRMkKa4moc=; b=mjW12qX4OzXz/M3ZG1i4a1p+lwFu7Kr6v5eWQJWfP3pJRY/RaQx3FyZQcQg9keNKa2 v0/pEHlM46divPzISBqU/vsbCTK4bPmZ0nCO9HLFgfdsEVRJhjHjqbV87ee5+lk3Q2a0 KlDFgj13f9/UsEElBWWlx+Rnr1F1JlsX/bvOpkA09X/0Qxljq+oLO7PNcK6NNh9lha1G SgZvvYycp13cZXKU8pC5gfRlqINbYTgvGMmhfBi1z52jM+//S3bI+o10FS0NY6LDHPCf 4baPEH/IsKog/N/JVoU0xZVAklFo4FIv2YjMjfeWgpJTnLoxt4YjWV7ZlAqx+UpPK84S 593Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Yy/VTgVE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q62-20020a17090a1b4400b00267f3363479si868109pjq.57.2023.07.26.23.43.51; Wed, 26 Jul 2023 23:44:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Yy/VTgVE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232439AbjG0FwK (ORCPT + 99 others); Thu, 27 Jul 2023 01:52:10 -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: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 *iommu) } EXPORT_SYMBOL_GPL(iommu_device_unregister); -static struct dev_iommu *dev_iommu_get(struct device *dev) +static int dev_iommu_get(struct device *dev) { struct dev_iommu *param = dev->iommu; if (param) - return param; + return 0; param = kzalloc(sizeof(*param), GFP_KERNEL); if (!param) - return NULL; + return -ENOMEM; mutex_init(¶m->lock); dev->iommu = param; - return param; + return 0; } 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; - if (!dev_iommu_get(dev)) - return -ENOMEM; + ret = dev_iommu_get(dev); + if (ret) + return ret; if (!try_module_get(ops->owner)) { ret = -EINVAL; @@ -2743,12 +2744,14 @@ int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, const struct iommu_ops *ops) { struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + int ret; if (fwspec) return ops == fwspec->ops ? 0 : -EINVAL; - if (!dev_iommu_get(dev)) - return -ENOMEM; + ret = dev_iommu_get(dev); + if (ret) + return ret; /* Preallocate for the overwhelmingly common case of 1 ID */ fwspec = kzalloc(struct_size(fwspec, ids, 1), GFP_KERNEL); -- 2.34.1