Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1200293 > unrolled thread
| Started by | "Luis R. Rodriguez" <mcgrof@do-not-panic.com> |
|---|---|
| First post | 2015-08-05 00:10 +0200 |
| Last post | 2015-08-05 00:10 +0200 |
| Articles | 4 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 0/4] firmware_class: few small code shifts "Luis R. Rodriguez" <mcgrof@do-not-panic.com> - 2015-08-05 00:10 +0200
[PATCH 2/4] firmware: move completing fw into a helper "Luis R. Rodriguez" <mcgrof@do-not-panic.com> - 2015-08-05 00:10 +0200
[PATCH 4/4] firmware: generalize reading file contents as a helper "Luis R. Rodriguez" <mcgrof@do-not-panic.com> - 2015-08-05 00:10 +0200
[PATCH 1/4] firmware: generalize "firmware" as "system data" helpers "Luis R. Rodriguez" <mcgrof@do-not-panic.com> - 2015-08-05 00:10 +0200
| From | "Luis R. Rodriguez" <mcgrof@do-not-panic.com> |
|---|---|
| Date | 2015-08-05 00:10 +0200 |
| Subject | [PATCH 0/4] firmware_class: few small code shifts |
| Message-ID | <pTSzg-70T-9@gated-at.bofh.it> |
From: "Luis R. Rodriguez" <mcgrof@suse.com> Ming, Greg, this patch set consists of a few small code shifts which would make it easier to add extensible firmware API code, and later firmware signing support. This patch set is being sent out separately as it does not contain any controversial changes. It should also help with readibility of the code. I'll be Cc'ing linux-doc, linux-security-module, and keyring folks as the next patch sets would start slowly diving into the topic of firmware signing and extending documentation, and those patches will depend on this set. There is a superfluous else branch on patch #3, its not needed because of the goto statement but we leave that in place to make patch #4 easier to read. David Howells (2): firmware: fold successful fw read early firmware: generalize reading file contents as a helper Luis R. Rodriguez (2): firmware: generalize "firmware" as "system data" helpers firmware: move completing fw into a helper drivers/base/firmware_class.c | 94 ++++++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 37 deletions(-) -- 2.3.2.209.gd67f9d5.dirty -- 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/
[toc] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@do-not-panic.com> |
|---|---|
| Date | 2015-08-05 00:10 +0200 |
| Subject | [PATCH 2/4] firmware: move completing fw into a helper |
| Message-ID | <pTSzh-70T-23@gated-at.bofh.it> |
| In reply to | #1200293 |
From: "Luis R. Rodriguez" <mcgrof@suse.com>
This will be re-used later through a new extensible interface.
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
drivers/base/firmware_class.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index f97e76cca069..9ee334c1b872 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -322,6 +322,15 @@ fail:
return rc;
}
+static void fw_finish_direct_load(struct device *device,
+ struct firmware_buf *buf)
+{
+ mutex_lock(&fw_lock);
+ set_bit(FW_STATUS_DONE, &buf->status);
+ complete_all(&buf->completion);
+ mutex_unlock(&fw_lock);
+}
+
static int fw_get_filesystem_firmware(struct device *device,
struct firmware_buf *buf)
{
@@ -363,10 +372,7 @@ static int fw_get_filesystem_firmware(struct device *device,
if (!rc) {
dev_dbg(device, "system data: direct-loading firmware %s\n",
buf->fw_id);
- mutex_lock(&fw_lock);
- set_bit(FW_STATUS_DONE, &buf->status);
- complete_all(&buf->completion);
- mutex_unlock(&fw_lock);
+ fw_finish_direct_load(device, buf);
}
return rc;
--
2.3.2.209.gd67f9d5.dirty
--
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/
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@do-not-panic.com> |
|---|---|
| Date | 2015-08-05 00:10 +0200 |
| Subject | [PATCH 4/4] firmware: generalize reading file contents as a helper |
| Message-ID | <pTSzg-70T-7@gated-at.bofh.it> |
| In reply to | #1200293 |
From: David Howells <dhowells@redhat.com>
We'll want to reuse this same code later in order to
read two separate types of file contents. This generalizes
fw_read_file() for reading a file rebrands it as fw_read_file().
This caller lets us pegs arbitrary data onto the target
buffer and size if the file is found.
While at it this cleans up the exit paths on fw_read_file().
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
drivers/base/firmware_class.c | 62 +++++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 23 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 736fb952b75b..dcc7036b4ad2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -291,34 +291,51 @@ static const char * const fw_path[] = {
module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);
MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
-static int fw_read_file_contents(struct file *file, struct firmware_buf *fw_buf)
+/*
+ * Read the contents of a file.
+ */
+static int fw_read_file(const char *path, void **_buf, size_t *_size)
{
- int size;
+ struct file *file;
+ size_t size;
char *buf;
int rc;
+ file = filp_open(path, O_RDONLY, 0);
+ if (IS_ERR(file))
+ return PTR_ERR(file);
+
+ rc = -EINVAL;
if (!S_ISREG(file_inode(file)->i_mode))
- return -EINVAL;
+ goto err_file;
size = i_size_read(file_inode(file));
if (size <= 0)
- return -EINVAL;
+ goto err_file;
+ rc = -ENOMEM;
buf = vmalloc(size);
if (!buf)
- return -ENOMEM;
+ goto err_file;
+
rc = kernel_read(file, 0, buf, size);
+ if (rc < 0)
+ goto err_buf;
if (rc != size) {
- if (rc > 0)
- rc = -EIO;
- goto fail;
+ rc = -EIO;
+ goto err_buf;
}
+
rc = security_kernel_fw_from_file(file, buf, size);
if (rc)
- goto fail;
- fw_buf->data = buf;
- fw_buf->size = size;
+ goto err_buf;
+
+ *_buf = buf;
+ *_size = size;
return 0;
-fail:
+
+err_buf:
vfree(buf);
+err_file:
+ fput(file);
return rc;
}
@@ -332,19 +349,21 @@ static void fw_finish_direct_load(struct device *device,
}
static int fw_get_filesystem_firmware(struct device *device,
- struct firmware_buf *buf)
+ struct firmware_buf *buf)
{
int i, len;
int rc = -ENOENT;
- char *path;
+ char *path = NULL;
path = __getname();
if (!path)
return -ENOMEM;
+ /*
+ * Try each possible firmware blob in turn till one doesn't produce
+ * ENOENT.
+ */
for (i = 0; i < ARRAY_SIZE(fw_path); i++) {
- struct file *file;
-
/* skip the unset customized path */
if (!fw_path[i][0])
continue;
@@ -356,23 +375,20 @@ static int fw_get_filesystem_firmware(struct device *device,
break;
}
- file = filp_open(path, O_RDONLY, 0);
- if (IS_ERR(file))
- continue;
- rc = fw_read_file_contents(file, buf);
- fput(file);
+ rc = fw_read_file(path, &buf->data, &buf->size);
if (rc == 0) {
dev_dbg(device, "system data: direct-loading firmware %s\n",
buf->fw_id);
fw_finish_direct_load(device, buf);
goto out;
- } else
+ } else if (rc != -ENOENT) {
dev_warn(device, "system data, attempted to load %s, but failed with error %d\n",
path, rc);
+ goto out;
+ }
}
out:
__putname(path);
-
return rc;
}
--
2.3.2.209.gd67f9d5.dirty
--
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/
[toc] | [prev] | [next] | [standalone]
| From | "Luis R. Rodriguez" <mcgrof@do-not-panic.com> |
|---|---|
| Date | 2015-08-05 00:10 +0200 |
| Subject | [PATCH 1/4] firmware: generalize "firmware" as "system data" helpers |
| Message-ID | <pTSzh-70T-41@gated-at.bofh.it> |
| In reply to | #1200293 |
From: "Luis R. Rodriguez" <mcgrof@suse.com>
Historically firmware_class code was added to help
get device driver firmware binaries but these days
request_firmware*() helpers are being repurposed for
general system data needed by the kernel.
Annotate this before we extend firmare_class more,
as this is expected. We want to generalize the code
as much as possible.
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Casey Schaufler <casey@schaufler-ca.com>
Cc: Ming Lei <ming.lei@canonical.com>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Vojtěch Pavlík <vojtech@suse.cz>
Cc: Kyle McMartin <kyle@kernel.org>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
drivers/base/firmware_class.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 894bda114224..f97e76cca069 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -353,15 +353,15 @@ static int fw_get_filesystem_firmware(struct device *device,
rc = fw_read_file_contents(file, buf);
fput(file);
if (rc)
- dev_warn(device, "firmware, attempted to load %s, but failed with error %d\n",
- path, rc);
+ dev_warn(device, "system data, attempted to load %s, but failed with error %d\n",
+ path, rc);
else
break;
}
__putname(path);
if (!rc) {
- dev_dbg(device, "firmware: direct-loading firmware %s\n",
+ dev_dbg(device, "system data: direct-loading firmware %s\n",
buf->fw_id);
mutex_lock(&fw_lock);
set_bit(FW_STATUS_DONE, &buf->status);
@@ -1051,7 +1051,7 @@ _request_firmware_prepare(struct firmware **firmware_p, const char *name,
}
if (fw_get_builtin_firmware(firmware, name)) {
- dev_dbg(device, "firmware: using built-in firmware %s\n", name);
+ dev_dbg(device, "system data: using built-in system data%s\n", name);
return 0; /* assigned */
}
--
2.3.2.209.gd67f9d5.dirty
--
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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web