Hi Luis,

Another question.

On 2020-05-12 5:33 p.m., Luis Chamberlain wrote:
On Thu, May 07, 2020 at 05:27:34PM -0700, Scott Branden wrote:
Add offset to request_firmware_into_buf to allow for portions
of firmware file to be read into a buffer.  Necessary where firmware
needs to be loaded in portions from file in memory constrained systems.

Signed-off-by: Scott Branden <scott.bran...@broadcom.com>
---
  drivers/base/firmware_loader/firmware.h |  5 +++
  drivers/base/firmware_loader/main.c     | 52 +++++++++++++++++--------
  drivers/soc/qcom/mdt_loader.c           |  7 +++-
  include/linux/firmware.h                |  8 +++-
  lib/test_firmware.c                     |  4 +-
  5 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/drivers/base/firmware_loader/firmware.h 
b/drivers/base/firmware_loader/firmware.h
index 25836a6afc9f..1147dae01148 100644
--- a/drivers/base/firmware_loader/firmware.h
+++ b/drivers/base/firmware_loader/firmware.h
@@ -32,6 +32,8 @@
   * @FW_OPT_FALLBACK_PLATFORM: Enable fallback to device fw copy embedded in
   *    the platform's main firmware. If both this fallback and the sysfs
   *      fallback are enabled, then this fallback will be tried first.
+ * @FW_OPT_PARTIAL: Allow partial read of firmware instead of needing to read
+ *     entire file.
See, this allows us use kdoc to document his nicely. Do that with the
kernel pread stuff.

@@ -68,6 +71,8 @@ struct fw_priv {
        void *data;
        size_t size;
        size_t allocated_size;
+       size_t offset;
+       unsigned int flags;
But flags is a misnomer, you just do two operations, just juse an enum
here to classify the read operation.

index 76f79913916d..4552b7bb819f 100644
--- a/drivers/base/firmware_loader/main.c
+++ b/drivers/base/firmware_loader/main.c
@@ -167,7 +167,8 @@ static int fw_cache_piggyback_on_request(const char *name);
static struct fw_priv *__allocate_fw_priv(const char *fw_name,
                                          struct firmware_cache *fwc,
-                                         void *dbuf, size_t size)
+                                         void *dbuf, size_t size,
+                                         size_t offset, unsigned int flags)
And likewise just use an enum here too.

@@ -210,9 +213,11 @@ static struct fw_priv *__lookup_fw_priv(const char 
*fw_name)
  static int alloc_lookup_fw_priv(const char *fw_name,
                                struct firmware_cache *fwc,
                                struct fw_priv **fw_priv, void *dbuf,
-                               size_t size, enum fw_opt opt_flags)
+                               size_t size, enum fw_opt opt_flags,
+                               size_t offset)
flags? But its a single variable enum!
fw_opt is an existing enum which doesn't really act like an enum.
It is a series of BIT defines in an enum that are then OR'd together in the (existing) code?

  {
        struct fw_priv *tmp;
+       unsigned int pread_flags;
spin_lock(&fwc->lock);
        if (!(opt_flags & FW_OPT_NOCACHE)) {
Have a look here - enum used as series of flags.
@@ -226,7 +231,12 @@ static int alloc_lookup_fw_priv(const char *fw_name,
                }
        }
- tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size);
+       if (opt_flags & FW_OPT_PARTIAL)
+               pread_flags = KERNEL_PREAD_FLAG_PART;
+       else
+               pread_flags = KERNEL_PREAD_FLAG_WHOLE;
+
+       tmp = __allocate_fw_priv(fw_name, fwc, dbuf, size, offset, pread_flags);
One of the advantages of using an enum is that you can then use a switch
here, and the compiler will warn if you haven't handled all the cases.
pread_flags is currently such.  I will change to enum pread_opt.

                /* load firmware files from the mount namespace of init */
-               rc = kernel_read_file_from_path_initns(path, &buffer,
-                                                      &size, msize, id);
+               rc = kernel_pread_file_from_path_initns(path, &buffer,
+                                                       &size, fw_priv->offset,
+                                                       msize,
+                                                       fw_priv->flags, id);
And here you'd just pass the kernel enum.
Yes, will change to fw_priv->opt and use enum for this one.

You get the idea, I stopped reviewing after this.

   Luis

Reply via email to