[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240222180033.23775-2-quic_mojha@quicinc.com>
Date: Thu, 22 Feb 2024 23:30:26 +0530
From: Mukesh Ojha <quic_mojha@...cinc.com>
To: <mcgrof@...nel.org>, <russ.weight@...ux.dev>, <gregkh@...uxfoundation.org>,
<rafael@...nel.org>
CC: <linux-kernel@...r.kernel.org>, Mukesh Ojha <quic_mojha@...cinc.com>
Subject: [PATCH vRFC 1/8] firmware_loader: Refactor request firmware lower level functions
Refactor low level api's to do code reuse.
Signed-off-by: Mukesh Ojha <quic_mojha@...cinc.com>
---
drivers/base/firmware_loader/main.c | 88 +++++++++++------------------
1 file changed, 34 insertions(+), 54 deletions(-)
diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c
index da8ca01d011c..645d658facae 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -739,7 +739,7 @@ int assign_fw(struct firmware *fw, struct device *device)
* or a negative error code
*/
static int
-_request_firmware_prepare(struct firmware **firmware_p, const char *name,
+__request_firmware_prepare(struct firmware **firmware_p, const char *name,
struct device *device, void *dbuf, size_t size,
size_t offset, u32 opt_flags)
{
@@ -851,9 +851,9 @@ static void fw_log_firmware_info(const struct firmware *fw, const char *name,
/* called from request_firmware() and request_firmware_work_func() */
static int
-_request_firmware(const struct firmware **firmware_p, const char *name,
- struct device *device, void *buf, size_t size,
- size_t offset, u32 opt_flags)
+__request_firmware(const struct firmware **firmware_p, const char *name,
+ struct device *device, void *buf, size_t size,
+ size_t offset, u32 opt_flags)
{
struct firmware *fw = NULL;
struct cred *kern_cred = NULL;
@@ -869,7 +869,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
goto out;
}
- ret = _request_firmware_prepare(&fw, name, device, buf, size,
+ ret = __request_firmware_prepare(&fw, name, device, buf, size,
offset, opt_flags);
if (ret <= 0) /* error or already assigned */
goto out;
@@ -932,6 +932,19 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
return ret;
}
+static int
+_request_firmware(const struct firmware **firmware_p, const char *name,
+ struct device *device, void *buf, size_t size,
+ size_t offset, u32 opt_flags)
+{
+ int ret;
+
+ /* Need to pin this module until return */
+ __module_get(THIS_MODULE);
+ ret = __request_firmware(firmware_p, name, device, NULL, 0, 0, opt_flags);
+ module_put(THIS_MODULE);
+ return ret;
+}
/**
* request_firmware() - send firmware request and wait for it
* @firmware_p: pointer to firmware image
@@ -956,14 +969,8 @@ int
request_firmware(const struct firmware **firmware_p, const char *name,
struct device *device)
{
- int ret;
-
- /* Need to pin this module until return */
- __module_get(THIS_MODULE);
- ret = _request_firmware(firmware_p, name, device, NULL, 0, 0,
- FW_OPT_UEVENT);
- module_put(THIS_MODULE);
- return ret;
+ return _request_firmware(firmware_p, name, device, NULL, 0, 0,
+ FW_OPT_UEVENT);
}
EXPORT_SYMBOL(request_firmware);
@@ -983,14 +990,8 @@ EXPORT_SYMBOL(request_firmware);
int firmware_request_nowarn(const struct firmware **firmware, const char *name,
struct device *device)
{
- int ret;
-
- /* Need to pin this module until return */
- __module_get(THIS_MODULE);
- ret = _request_firmware(firmware, name, device, NULL, 0, 0,
- FW_OPT_UEVENT | FW_OPT_NO_WARN);
- module_put(THIS_MODULE);
- return ret;
+ return _request_firmware(firmware, name, device, NULL, 0, 0,
+ FW_OPT_UEVENT | FW_OPT_NO_WARN);
}
EXPORT_SYMBOL_GPL(firmware_request_nowarn);
@@ -1008,14 +1009,9 @@ EXPORT_SYMBOL_GPL(firmware_request_nowarn);
int request_firmware_direct(const struct firmware **firmware_p,
const char *name, struct device *device)
{
- int ret;
-
- __module_get(THIS_MODULE);
- ret = _request_firmware(firmware_p, name, device, NULL, 0, 0,
- FW_OPT_UEVENT | FW_OPT_NO_WARN |
- FW_OPT_NOFALLBACK_SYSFS);
- module_put(THIS_MODULE);
- return ret;
+ return _request_firmware(firmware_p, name, device, NULL, 0, 0,
+ FW_OPT_UEVENT | FW_OPT_NO_WARN |
+ FW_OPT_NOFALLBACK_SYSFS);
}
EXPORT_SYMBOL_GPL(request_firmware_direct);
@@ -1032,14 +1028,8 @@ EXPORT_SYMBOL_GPL(request_firmware_direct);
int firmware_request_platform(const struct firmware **firmware,
const char *name, struct device *device)
{
- int ret;
-
- /* Need to pin this module until return */
- __module_get(THIS_MODULE);
- ret = _request_firmware(firmware, name, device, NULL, 0, 0,
- FW_OPT_UEVENT | FW_OPT_FALLBACK_PLATFORM);
- module_put(THIS_MODULE);
- return ret;
+ return _request_firmware(firmware, name, device, NULL, 0, 0,
+ FW_OPT_UEVENT | FW_OPT_FALLBACK_PLATFORM);
}
EXPORT_SYMBOL_GPL(firmware_request_platform);
@@ -1086,16 +1076,11 @@ int
request_firmware_into_buf(const struct firmware **firmware_p, const char *name,
struct device *device, void *buf, size_t size)
{
- int ret;
-
if (fw_cache_is_setup(device, name))
return -EOPNOTSUPP;
- __module_get(THIS_MODULE);
- ret = _request_firmware(firmware_p, name, device, buf, size, 0,
- FW_OPT_UEVENT | FW_OPT_NOCACHE);
- module_put(THIS_MODULE);
- return ret;
+ return _request_firmware(firmware_p, name, device, buf, size, 0,
+ FW_OPT_UEVENT | FW_OPT_NOCACHE);
}
EXPORT_SYMBOL(request_firmware_into_buf);
@@ -1116,17 +1101,12 @@ request_partial_firmware_into_buf(const struct firmware **firmware_p,
const char *name, struct device *device,
void *buf, size_t size, size_t offset)
{
- int ret;
-
if (fw_cache_is_setup(device, name))
return -EOPNOTSUPP;
- __module_get(THIS_MODULE);
- ret = _request_firmware(firmware_p, name, device, buf, size, offset,
- FW_OPT_UEVENT | FW_OPT_NOCACHE |
- FW_OPT_PARTIAL);
- module_put(THIS_MODULE);
- return ret;
+ return _request_firmware(firmware_p, name, device, buf, size, offset,
+ FW_OPT_UEVENT | FW_OPT_NOCACHE |
+ FW_OPT_PARTIAL);
}
EXPORT_SYMBOL(request_partial_firmware_into_buf);
@@ -1162,8 +1142,8 @@ static void request_firmware_work_func(struct work_struct *work)
fw_work = container_of(work, struct firmware_work, work);
- _request_firmware(&fw, fw_work->name, fw_work->device, NULL, 0, 0,
- fw_work->opt_flags);
+ __request_firmware(&fw, fw_work->name, fw_work->device, NULL, 0, 0,
+ fw_work->opt_flags);
fw_work->cont(fw, fw_work->context);
put_device(fw_work->device); /* taken in request_firmware_nowait() */
--
2.43.0.254.ga26002b62827
Powered by blists - more mailing lists