From: Mimi Zohar <zohar@linux.vnet.ibm.com>
To: Stephen Boyd <stephen.boyd@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-arm@lists.infradead.org,
Andrew Morton <akpm@linux-foundation.org>,
Mark Brown <broonie@kernel.org>,
Ming Lei <ming.lei@canonical.com>,
Vikram Mulukutla <markivx@codeaurora.org>
Subject: Re: [RFC/PATCHv3 v3 3/3] firmware: Support loading into a pre-allocated buffer
Date: Wed, 11 May 2016 08:41:52 -0400 [thread overview]
Message-ID: <1462970512.12106.91.camel@linux.vnet.ibm.com> (raw)
In-Reply-To: <1462919163-2503-4-git-send-email-stephen.boyd@linaro.org>
Hi Stephen,
On Tue, 2016-05-10 at 15:26 -0700, Stephen Boyd wrote:
> -static int fw_get_filesystem_firmware(struct device *device,
> - struct firmware_buf *buf)
> +static int
> +fw_get_filesystem_firmware(struct device *device, struct firmware_buf *buf)
> {
> loff_t size;
> int i, len;
> int rc = -ENOENT;
> char *path;
> + enum kernel_read_file_id id = READING_FIRMWARE;
> + size_t msize = INT_MAX;
> +
> + /* Already populated data member means we're loading into a buffer */
> + if (buf->data) {
> + id = READING_FIRMWARE_INTO_BUF;
In both cases we're reading the firmware into a buffer. In this case,
it is pre-allocated. Other than it being pre-allocated, is there
anything special about this buffer? There has to be a more appropriate
string identifier.
> + msize = buf->allocated_size;
> + }
>
> path = __getname();
> if (!path)
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -836,8 +836,8 @@ int kernel_read(struct file *file, loff_t offset,
>
> EXPORT_SYMBOL(kernel_read);
>
> -int kernel_read_file(struct file *file, void **buf, loff_t *size,
> - loff_t max_size, enum kernel_read_file_id id)
> +static int _kernel_read_file(struct file *file, void **buf, loff_t *size,
> + loff_t max_size, enum kernel_read_file_id id)
> {
> loff_t i_size, pos;
> ssize_t bytes = 0;
> @@ -856,7 +856,8 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
> if (i_size <= 0)
> return -EINVAL;
>
> - *buf = vmalloc(i_size);
> + if (id != READING_FIRMWARE_INTO_BUF)
> + *buf = vmalloc(i_size);
> if (!*buf)
> return -ENOMEM;
>
> @@ -885,11 +886,19 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size,
>
> out:
> if (ret < 0) {
> - vfree(*buf);
> - *buf = NULL;
> + if (id != READING_FIRMWARE_INTO_BUF) {
> + vfree(*buf);
> + *buf = NULL;
> + }
> }
> return ret;
> }
> +
> +int kernel_read_file(struct file *file, void **buf, loff_t *size,
> + loff_t max_size, enum kernel_read_file_id id)
> +{
> + return _kernel_read_file(file, buf, size, max_size, id);
> +}
> EXPORT_SYMBOL_GPL(kernel_read_file);
This seems to be exactly the same as the original version.
>
> int kernel_read_file_from_path(char *path, void **buf, loff_t *size,
> @@ -905,7 +914,7 @@ int kernel_read_file_from_path(char *path, void **buf, loff_t *size,
> if (IS_ERR(file))
> return PTR_ERR(file);
>
> - ret = kernel_read_file(file, buf, size, max_size, id);
> + ret = _kernel_read_file(file, buf, size, max_size, id);
> fput(file);
> return ret;
> }
> diff --git a/include/linux/firmware.h b/include/linux/firmware.h
> index 5c41c5e75b5c..bdc24ee92823 100644
> --- a/include/linux/firmware.h
> +++ b/include/linux/firmware.h
> @@ -47,6 +47,8 @@ int request_firmware_nowait(
> void (*cont)(const struct firmware *fw, void *context));
> int request_firmware_direct(const struct firmware **fw, const char *name,
> struct device *device);
> +int request_firmware_into_buf(const struct firmware **firmware_p,
> + const char *name, struct device *device, void *buf, size_t size);
>
> void release_firmware(const struct firmware *fw);
> #else
> @@ -75,5 +77,11 @@ static inline int request_firmware_direct(const struct firmware **fw,
> return -EINVAL;
> }
>
> +static inline int request_firmware_into_buf(const struct firmware **firmware_p,
> + const char *name, struct device *device, void *buf, size_t size);
> +{
> + return -EINVAL;
> +}
> +
> #endif
> #endif
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 14a97194b34b..4fb8596b3dd4 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2582,6 +2582,7 @@ extern int do_pipe_flags(int *, int);
>
> enum kernel_read_file_id {
> READING_FIRMWARE = 1,
> + READING_FIRMWARE_INTO_BUF,
> READING_MODULE,
> READING_KEXEC_IMAGE,
> READING_KEXEC_INITRAMFS,
Commit "1284ab5 fs: define a string representation of the
kernel_read_file_id enumeration", which is queued to be upstreamed,
changes this a bit.
> diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
> index 60d011aaec38..b922d6ca2fb0 100644
> --- a/security/integrity/ima/ima_fs.c
> +++ b/security/integrity/ima/ima_fs.c
> @@ -272,7 +272,8 @@ static ssize_t ima_read_policy(char *path)
> datap = path;
> strsep(&datap, "\n");
>
> - rc = kernel_read_file_from_path(path, &data, &size, 0, READING_POLICY);
> + rc = kernel_read_file_from_path(path, &data, &size, 0, READING_POLICY,
> + NULL);
It doesn't look like kernel_read_file_from_path() changed.
Mimi
> if (rc < 0) {
> pr_err("Unable to open file: %s (%d)", path, rc);
> return rc;
next prev parent reply other threads:[~2016-05-11 12:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 22:26 [RFC/PATCHv3 v3 0/3] request_firmware() into pre-allocated buffers Stephen Boyd
2016-05-10 22:26 ` [RFC/PATCHv3 v3 1/3] firmware: Consolidate kmap/read/write logic Stephen Boyd
2016-05-10 22:26 ` [RFC/PATCHv3 v3 2/3] firmware: Provide infrastructure to make fw caching optional Stephen Boyd
2016-05-10 22:26 ` [RFC/PATCHv3 v3 3/3] firmware: Support loading into a pre-allocated buffer Stephen Boyd
2016-05-11 12:41 ` Mimi Zohar [this message]
[not found] ` <20160511202231.8857.86068@sboyd-linaro>
2016-05-11 20:46 ` Mimi Zohar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462970512.12106.91.camel@linux.vnet.ibm.com \
--to=zohar@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=broonie@kernel.org \
--cc=linux-arm@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=markivx@codeaurora.org \
--cc=ming.lei@canonical.com \
--cc=stephen.boyd@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.