Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3629686pxb; Tue, 19 Apr 2022 06:57:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxe1HjGPeg19QC88/ehn6Zmm3tSdd1P0sT7Ch/CNyQiC49XqaZ5qToIPfa7gtaiKiViS6rs X-Received: by 2002:a63:2c4c:0:b0:398:997d:b5b8 with SMTP id s73-20020a632c4c000000b00398997db5b8mr14847380pgs.86.1650376623143; Tue, 19 Apr 2022 06:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650376623; cv=none; d=google.com; s=arc-20160816; b=P2K/lC/w+P34WxCBQAVaKRo+8UuDClTe+l9z+j5YQrAXVgLDfsTWPVgilJkCb+4lsv NUaJh7YQlcXENS6ooFUEgU1rDTIQZtObwhdfxRiCOmXmm1rnbNaTebGKqXwb5rPyNWOe 3GcuQGnp+vvDgjHDroIhyv9aBgFILLftzp1sLER1KOIQ/qzfcP/1UX14xXlUI10c5Kco nUi5m3iVM6LcU339fSja4p4DOBxpNtCXTYTg1JlHtvAklKoYJZ9o5DufU7S4SJEjgZtK YFg+v//Plx6Telw6D5y8CkWaEqGwr0QLx2pacxI1fa7CHMSgq4kq/cMt8/Nzm22us9gD NFUA== 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=aIcpzrcTgYuC4OnH0l1dViOAgjjuzb5HHJtN5hdd3EI=; b=HA6V8q4vc6MAvy8wbmd/6YYgQnQxI02rTiyCOqW9m7C29bNjsYvCak3QFj0yAAF0lG v4bOzoGQ5AUhdTUAETzRm6cXIHUuDBSTyNjnHtxGoAYfgowuq2SJnUcoIgPU+DY5esPl l4USZ/YEEfFay40U77Yit4h4TvEj/bz/BMTLJp8L9WD/MbTa5DjjwF24hhksUm6aUCO+ EHA3N4Cd6hmbrAMM3NPBw1WKN50jyuJ2+gS4ARvH7cxq7GnsHYFMParZz06V9DYwgqxR 5hbvPf8iWssOcrOL1YJmIcpweeszz7SmlWbwoV4waZGDfl5F+gEcltWVsGqSoXmPxwf4 KYZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YVjaZNj3; 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 e3-20020a170902ef4300b00153b2d16629si11348674plx.561.2022.04.19.06.56.41; Tue, 19 Apr 2022 06:57: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=YVjaZNj3; 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 S232128AbiDRWk5 (ORCPT + 99 others); Mon, 18 Apr 2022 18:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231987AbiDRWkt (ORCPT ); Mon, 18 Apr 2022 18:40:49 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E45622B21 for ; Mon, 18 Apr 2022 15:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650321489; x=1681857489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vkq+wypS+ttQqXKmCnsOvo0jkDNKr3rnK/6BnXGKgvE=; b=YVjaZNj3Mo5NLE7D1cpQfEA6d7YpUWhBqJ/wrQDFlIa5Fm624wghZMZ2 Y9zC8tR8nVmgkNBlfRwU4nmsH6opcsm9V5ysJv6lk3ukhWqbdHPXK07RF peAQm4fcvw3g8EfUZFSZo5zdrEP0iw3aqYFDKd/KmwBfPcubl2jI8aYrh nI94iDxnW/QccniqcpUbd0luu3oqEFUqYVx19TBuXbPESS7/kwBPINW4e CQW+ZyrSFm41ET+dWeQ9F8Ef6bqRRajzNw7WxQqTu7i2VAREZSUvCF9M7 W1qiqL2Dl/wZ4hF+lyIOLlR+wgaTv3auNPn6smNMCIbOE+CLShlGMZnb1 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10321"; a="243557444" X-IronPort-AV: E=Sophos;i="5.90,271,1643702400"; d="scan'208";a="243557444" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 15:38:09 -0700 X-IronPort-AV: E=Sophos;i="5.90,271,1643702400"; d="scan'208";a="509907097" Received: from rhweight-mobl.amr.corp.intel.com (HELO rhweight-mobl.ra.intel.com) ([10.209.35.137]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 15:38:05 -0700 From: Russ Weight To: mcgrof@kernel.org, rafael@kernel.org, linux-kernel@vger.kernel.org Cc: trix@redhat.com, lgoncalv@redhat.com, yilun.xu@intel.com, hao.wu@intel.com, matthew.gerlach@linux.intel.com, basheer.ahmed.muddebihal@intel.com, tianfei.zhang@intel.com, Russ Weight Subject: [PATCH v3 2/8] firmware_loader: Check fw_state_is_done in loading_store Date: Mon, 18 Apr 2022 15:37:47 -0700 Message-Id: <20220418223753.639058-3-russell.h.weight@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220418223753.639058-1-russell.h.weight@intel.com> References: <20220418223753.639058-1-russell.h.weight@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,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 Rename fw_sysfs_done() and fw_sysfs_loading() to fw_state_is_done() and fw_state_is_loading() respectively, and place them along side companion functions in drivers/base/firmware_loader/firmware.h. Use the fw_state_is_done() function to exit early from firmware_loading_store() if the state is already "done". This is being done in preparation for supporting persistent sysfs nodes to allow userspace to upload firmware to a device, potentially reusing the sysfs loading and data files multiple times. Reviewed-by: Luis Chamberlain Signed-off-by: Russ Weight --- v1: - No change from RFC patch v2: - It was discovered that the new function in v1, fw_state_is_done(), is equivalent to the existing fw_sysfs_done() function. Renamed fw_sysfs_done() and fw_sysfs_loading() to fw_state_is_done() and fw_state_is_loading() respectively, and placed them along side companion functions in drivers/base/firmware_loader/firmware.h. - Removed the "if !fw_sysfs_done(fw_priv))" condition in switch case 1 of firmware_loading_store(). It is rendered unnecessary by other changes to the function by this patch. v3: - Added Reviewed-by tag --- drivers/base/firmware_loader/fallback.c | 28 +++++++------------------ drivers/base/firmware_loader/firmware.h | 10 +++++++++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c index 4afb0e9312c0..8063eb595719 100644 --- a/drivers/base/firmware_loader/fallback.c +++ b/drivers/base/firmware_loader/fallback.c @@ -58,16 +58,6 @@ static long firmware_loading_timeout(void) __firmware_loading_timeout() * HZ : MAX_JIFFY_OFFSET; } -static inline bool fw_sysfs_done(struct fw_priv *fw_priv) -{ - return __fw_state_check(fw_priv, FW_STATUS_DONE); -} - -static inline bool fw_sysfs_loading(struct fw_priv *fw_priv) -{ - return __fw_state_check(fw_priv, FW_STATUS_LOADING); -} - static inline int fw_sysfs_wait_timeout(struct fw_priv *fw_priv, long timeout) { return __fw_state_wait_common(fw_priv, timeout); @@ -91,7 +81,7 @@ static void __fw_load_abort(struct fw_priv *fw_priv) * There is a small window in which user can write to 'loading' * between loading done/aborted and disappearance of 'loading' */ - if (fw_state_is_aborted(fw_priv) || fw_sysfs_done(fw_priv)) + if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv)) return; fw_state_aborted(fw_priv); @@ -220,7 +210,7 @@ static ssize_t firmware_loading_show(struct device *dev, mutex_lock(&fw_lock); if (fw_sysfs->fw_priv) - loading = fw_sysfs_loading(fw_sysfs->fw_priv); + loading = fw_state_is_loading(fw_sysfs->fw_priv); mutex_unlock(&fw_lock); return sysfs_emit(buf, "%d\n", loading); @@ -250,19 +240,17 @@ static ssize_t firmware_loading_store(struct device *dev, mutex_lock(&fw_lock); fw_priv = fw_sysfs->fw_priv; - if (fw_state_is_aborted(fw_priv)) + if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv)) goto out; switch (loading) { case 1: /* discarding any previous partial load */ - if (!fw_sysfs_done(fw_priv)) { - fw_free_paged_buf(fw_priv); - fw_state_start(fw_priv); - } + fw_free_paged_buf(fw_priv); + fw_state_start(fw_priv); break; case 0: - if (fw_sysfs_loading(fw_priv)) { + if (fw_state_is_loading(fw_priv)) { int rc; /* @@ -350,7 +338,7 @@ static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj, mutex_lock(&fw_lock); fw_priv = fw_sysfs->fw_priv; - if (!fw_priv || fw_sysfs_done(fw_priv)) { + if (!fw_priv || fw_state_is_done(fw_priv)) { ret_count = -ENODEV; goto out; } @@ -410,7 +398,7 @@ static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj, mutex_lock(&fw_lock); fw_priv = fw_sysfs->fw_priv; - if (!fw_priv || fw_sysfs_done(fw_priv)) { + if (!fw_priv || fw_state_is_done(fw_priv)) { retval = -ENODEV; goto out; } diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h index 2889f446ad41..d5ff32a1ba2d 100644 --- a/drivers/base/firmware_loader/firmware.h +++ b/drivers/base/firmware_loader/firmware.h @@ -149,6 +149,16 @@ static inline void fw_state_done(struct fw_priv *fw_priv) __fw_state_set(fw_priv, FW_STATUS_DONE); } +static inline bool fw_state_is_done(struct fw_priv *fw_priv) +{ + return __fw_state_check(fw_priv, FW_STATUS_DONE); +} + +static inline bool fw_state_is_loading(struct fw_priv *fw_priv) +{ + return __fw_state_check(fw_priv, FW_STATUS_LOADING); +} + int assign_fw(struct firmware *fw, struct device *device); #ifdef CONFIG_FW_LOADER -- 2.25.1