Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753118AbaKCDEU (ORCPT ); Sun, 2 Nov 2014 22:04:20 -0500 Received: from mga14.intel.com ([192.55.52.115]:19277 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753035AbaKCDEQ (ORCPT ); Sun, 2 Nov 2014 22:04:16 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="410147587" From: Kweh Hock Leong To: Matt Fleming , Ming Lei , Sam Protsenko Cc: Greg Kroah-Hartman , LKML , linux-efi@vger.kernel.org, Ong Boon Leong , Kweh Hock Leong Subject: [PATCH v2 1/3] firmware loader: Introduce new API - request_firmware_abort() Date: Mon, 3 Nov 2014 11:07:08 +0800 Message-Id: <1414984030-13859-2-git-send-email-hock.leong.kweh@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414984030-13859-1-git-send-email-hock.leong.kweh@intel.com> References: <1414984030-13859-1-git-send-email-hock.leong.kweh@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kweh, Hock Leong" Besides aborting through user helper interface, a new API request_firmware_abort() allows kernel driver module to abort the request_firmware() / request_firmware_nowait() when they are no longer needed. It is useful for cancelling an outstanding firmware load if initiated from inside a module where that module is in the process of being unloaded, since the unload function may not have a handle to the struct firmware_buf. Note for people who use request_firmware_nowait(): You are required to do your own synchronization after you call request_firmware_abort() in order to continue unloading the module. The example synchronization code shows below: while (THIS_MODULE && module_refcount(THIS_MODULE)) msleep(20); Cc: Matt Fleming Signed-off-by: Kweh, Hock Leong --- drivers/base/firmware_class.c | 52 +++++++++++++++++++++++++++++++---------- include/linux/firmware.h | 4 ++++ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index d276e33..a238a46 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -1291,6 +1291,46 @@ request_firmware_nowait( } EXPORT_SYMBOL(request_firmware_nowait); +static struct firmware_buf *fw_lookup_buf(const char *fw_name) +{ + struct firmware_buf *tmp; + struct firmware_cache *fwc = &fw_cache; + + spin_lock(&fwc->lock); + tmp = __fw_lookup_buf(fw_name); + spin_unlock(&fwc->lock); + + return tmp; +} + +/** + * request_firmware_abort - abort the waiting of firmware request + * @fw_name: name of firmware file + * + * @fw_name is the same name string while calling to request_firmware() + * or request_firmware_nowait(). + **/ +int request_firmware_abort(const char *fw_name) +{ + struct firmware_buf *buf; + struct firmware_buf *entry; + + buf = fw_lookup_buf(fw_name); + if (!buf) + return -ENOENT; + + mutex_lock(&fw_lock); + list_for_each_entry(entry, &pending_fw_head, pending_list) { + if (entry == buf) { + __fw_load_abort(buf); + break; + } + } + mutex_unlock(&fw_lock); + return 0; +} +EXPORT_SYMBOL(request_firmware_abort); + #ifdef CONFIG_PM_SLEEP static ASYNC_DOMAIN_EXCLUSIVE(fw_cache_domain); @@ -1324,18 +1364,6 @@ static int cache_firmware(const char *fw_name) return ret; } -static struct firmware_buf *fw_lookup_buf(const char *fw_name) -{ - struct firmware_buf *tmp; - struct firmware_cache *fwc = &fw_cache; - - spin_lock(&fwc->lock); - tmp = __fw_lookup_buf(fw_name); - spin_unlock(&fwc->lock); - - return tmp; -} - /** * uncache_firmware - remove one cached firmware image * @fw_name: the firmware image name diff --git a/include/linux/firmware.h b/include/linux/firmware.h index 5952933..ed90c8b 100644 --- a/include/linux/firmware.h +++ b/include/linux/firmware.h @@ -47,6 +47,7 @@ int request_firmware_nowait( void (*cont)(const struct firmware *fw, void *context)); void release_firmware(const struct firmware *fw); +int request_firmware_abort(const char *fw_name); #else static inline int request_firmware(const struct firmware **fw, const char *name, @@ -66,6 +67,9 @@ static inline void release_firmware(const struct firmware *fw) { } +static inline int request_firmware_abort(const char *fw_name) +{ +} #endif #ifdef CONFIG_FW_LOADER_USER_HELPER -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/