From: Ido Yariv <ido@wizery.com>
To: sjur.brandeland@stericsson.com
Cc: Ohad Ben-Cohen <ohad@wizery.com>,
linux-kernel@vger.kernel.org,
Dmitry Tarnyagin <dmitry.tarnyagin@stericsson.com>,
Linus Walleij <linus.walleij@linaro.org>,
Erwan Yvin <erwan.yvin@stericsson.com>,
sjur@brendeland.net
Subject: Re: [PATCH 2/9] remoteproc: Refactor function rproc_elf_find_rsc_table
Date: Wed, 20 Feb 2013 12:44:18 +0200 [thread overview]
Message-ID: <20130220104418.GB16388@WorkStation.localnet> (raw)
In-Reply-To: <1360496352-29482-3-git-send-email-sjur.brandeland@stericsson.com>
Hi Sjur,
Sorry for the (very) late reply.
On Sun, Feb 10, 2013 at 12:39:05PM +0100, sjur.brandeland@stericsson.com wrote:
> From: Sjur Brændeland <sjur.brandeland@stericsson.com>
>
> Refactor rproc_elf_find_rsc_table and split out the scanning
> for the section header named resource table. This is done to
> prepare for loading firmware once.
>
> Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
> ---
> drivers/remoteproc/remoteproc_elf_loader.c | 79 ++++++++++++++++++----------
> 1 files changed, 52 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
> index 0d36f94..a958950 100644
> --- a/drivers/remoteproc/remoteproc_elf_loader.c
> +++ b/drivers/remoteproc/remoteproc_elf_loader.c
> @@ -208,38 +208,19 @@ rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
> return ret;
> }
>
> -/**
> - * rproc_elf_find_rsc_table() - find the resource table
> - * @rproc: the rproc handle
> - * @fw: the ELF firmware image
> - * @tablesz: place holder for providing back the table size
> - *
> - * This function finds the resource table inside the remote processor's
> - * firmware. It is used both upon the registration of @rproc (in order
> - * to look for and register the supported virito devices), and when the
> - * @rproc is booted.
> - *
> - * Returns the pointer to the resource table if it is found, and write its
> - * size into @tablesz. If a valid table isn't found, NULL is returned
> - * (and @tablesz isn't set).
> - */
> -static struct resource_table *
> -rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
> - int *tablesz)
> +static struct elf32_shdr *
> +find_rsc_shdr(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size)
> {
> - struct elf32_hdr *ehdr;
> struct elf32_shdr *shdr;
> + int i;
> const char *name_table;
> - struct device *dev = &rproc->dev;
> struct resource_table *table = NULL;
> - int i;
> - const u8 *elf_data = fw->data;
> + const u8 *elf_data = (void *)ehdr;
>
> - ehdr = (struct elf32_hdr *)elf_data;
> + /* look for the resource table and handle it */
> shdr = (struct elf32_shdr *)(elf_data + ehdr->e_shoff);
> name_table = elf_data + shdr[ehdr->e_shstrndx].sh_offset;
>
> - /* look for the resource table and handle it */
> for (i = 0; i < ehdr->e_shnum; i++, shdr++) {
> int size = shdr->sh_size;
> int offset = shdr->sh_offset;
> @@ -250,7 +231,7 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
> table = (struct resource_table *)(elf_data + offset);
>
> /* make sure we have the entire table */
> - if (offset + size > fw->size) {
> + if (offset + size > fw_size) {
While we're at it, perhaps also verify that there aren't any integer overflows
here?
> dev_err(dev, "resource table truncated\n");
> return NULL;
> }
> @@ -280,10 +261,54 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
> return NULL;
> }
>
> - *tablesz = shdr->sh_size;
> - break;
> + return shdr;
> }
>
> + return NULL;
> +}
> +
> +/**
> + * rproc_elf_find_rsc_table() - find the resource table
> + * @rproc: the rproc handle
> + * @fw: the ELF firmware image
> + * @tablesz: place holder for providing back the table size
> + *
> + * This function finds the resource table inside the remote processor's
> + * firmware. It is used both upon the registration of @rproc (in order
> + * to look for and register the supported virito devices), and when the
> + * @rproc is booted.
> + *
> + * Returns the pointer to the resource table if it is found, and write its
> + * size into @tablesz. If a valid table isn't found, NULL is returned
> + * (and @tablesz isn't set).
> + */
> +static struct resource_table *
> +rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
> + int *tablesz)
> +{
> + struct elf32_hdr *ehdr;
> + struct elf32_shdr *shdr;
> +
> + struct device *dev = &rproc->dev;
> + struct resource_table *table = NULL;
> +
> + const u8 *elf_data = fw->data;
> +
Mind removing empty lines here?
> + ehdr = (struct elf32_hdr *)elf_data;
> +
> + shdr = find_rsc_shdr(dev, ehdr, fw->size);
> + if (!shdr)
> + return NULL;
> +
> + /* make sure we have the entire table */
> + if (shdr->sh_offset + shdr->sh_size > fw->size) {
> + dev_err(dev, "resource table truncated\n");
> + return NULL;
> + }
Any reason for this explicit assertion? It seemed to be checked in
find_rsc_shdr.
> +
> + table = (struct resource_table *)(elf_data + shdr->sh_offset);
> + *tablesz = shdr->sh_size;
> +
> return table;
> }
>
> --
> 1.7.5.4
>
Thanks,
Ido.
next prev parent reply other threads:[~2013-02-20 10:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-10 11:39 [PATCH 0/9] remoteproc: Support bi-directional vdev config space sjur.brandeland
2013-02-10 11:39 ` [PATCH 1/9] remoteproc: Bugfix: Deallocate firmware image on shutdown sjur.brandeland
2013-03-19 12:37 ` Ohad Ben-Cohen
2013-03-19 12:40 ` Sjur BRENDELAND
2013-03-19 13:15 ` Ohad Ben-Cohen
2013-02-10 11:39 ` [PATCH 2/9] remoteproc: Refactor function rproc_elf_find_rsc_table sjur.brandeland
2013-02-20 10:44 ` Ido Yariv [this message]
2013-02-10 11:39 ` [PATCH 3/9] remoteproc: Parse ELF file to find resource table address sjur.brandeland
2013-02-20 10:44 ` Ido Yariv
2013-02-10 11:39 ` [PATCH 4/9] remoteproc: Parse STE-firmware and " sjur.brandeland
2013-02-10 11:39 ` [PATCH 5/9] remoteproc: Set vring addresses in resource table sjur.brandeland
2013-02-10 11:39 ` [PATCH 6/9] remoteproc: Support virtio config space sjur.brandeland
2013-02-20 10:45 ` Ido Yariv
2013-02-10 11:39 ` [PATCH 7/9] remoteproc: Code cleanup of resource parsing sjur.brandeland
2013-02-10 11:39 ` [PATCH 8/9] remoteproc: Calculate max_notifyid by counting vrings sjur.brandeland
2013-02-20 10:45 ` Ido Yariv
2013-02-10 11:39 ` [PATCH 9/9] remoteproc: Always perserve resource table data sjur.brandeland
2013-02-20 10:46 ` Ido Yariv
2013-02-21 15:56 ` Sjur Brændeland
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=20130220104418.GB16388@WorkStation.localnet \
--to=ido@wizery.com \
--cc=dmitry.tarnyagin@stericsson.com \
--cc=erwan.yvin@stericsson.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ohad@wizery.com \
--cc=sjur.brandeland@stericsson.com \
--cc=sjur@brendeland.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox