From patchwork Thu Jul 27 05:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolu Lu X-Patchwork-Id: 126681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp894883vqo; Wed, 26 Jul 2023 23:39:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlGJwlJJE9DnFkl/ReIvN6KQKFX+Z2jabQva1L7GWTM+btD6wG59vhmbBafX3T9tAjH8WBoD X-Received: by 2002:a05:6a20:4289:b0:134:d4d3:f0a7 with SMTP id o9-20020a056a20428900b00134d4d3f0a7mr4677748pzj.9.1690439956563; Wed, 26 Jul 2023 23:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690439956; cv=none; d=google.com; s=arc-20160816; b=J/tLVMGJnPuSvpQl+q41886zgu6c8Y0avy2nsfEdX1/fcuIn9k7Nzb29Q6UWFnokQd 2oDkf1c+ugeP/nynTSf5WEMwmy7q9S2ym78mFnyw0ntuGs2T3lUH/2oKCZcgJcmqDRkq 9mZUHSoyk0vkZgEnt+qqbBqMBKnDay+3O5lxIINMRgocLMlDkezxk/4zbj6ZIZL9ZYu0 FvBnN8YJBS8o5KQXPWo+SZLj3JzCEYTmQ+bPI8fKt8pufSkGlzeRxScIQf7zXP0SRIq6 RWQ2o9Z8q13J5s9MRTBq2YqtDtzHoa2wTARzJpDNhf334ItlAr8TDmNnK9Q6DsEsvv8Z mbvA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a170902d4c500b001b3c7e6a8c0si841845plg.531.2023.07.26.23.39.02; Wed, 26 Jul 2023 23:39:16 -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 S232461AbjG0FwL (ORCPT + 99 others); Thu, 27 Jul 2023 01:52:11 -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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772554767826834973 X-GMAIL-MSGID: 1772554767826834973 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);