[PATCH 3/4] kexec/kexec-zlib.h: Add 'is_zlib_file()' helper function

Bhupesh Sharma bhsharma at redhat.com
Fri Jul 12 01:06:52 PDT 2019


Hi Simon,

On Thu, Jul 11, 2019 at 3:28 PM Simon Horman <horms at verge.net.au> wrote:
>
> On Thu, Jul 11, 2019 at 01:24:28AM +0530, Bhupesh Sharma wrote:
> > This patch adds 'is_zlib_file()' helper function which can be
> > used to quickly determine with the passed kernel image is a zlib
> > compressed kernel image.
> >
> > This is specifically useful for arm64 zImage (or Image.gz) support,
> > which is introduced by later patches in this patchset.
> >
> > Signed-off-by: Bhupesh Sharma <bhsharma at redhat.com>
> > ---
> >  kexec/kexec-zlib.h |  1 +
> >  kexec/zlib.c       | 32 ++++++++++++++++++++++++++++++++
> >  2 files changed, 33 insertions(+)
> >
> > diff --git a/kexec/kexec-zlib.h b/kexec/kexec-zlib.h
> > index 43c107bf4a72..16300f294759 100644
> > --- a/kexec/kexec-zlib.h
> > +++ b/kexec/kexec-zlib.h
> > @@ -6,5 +6,6 @@
> >
> >  #include "config.h"
> >
> > +int is_zlib_file(const char *filename, off_t *r_size);
> >  char *zlib_decompress_file(const char *filename, off_t *r_size);
> >  #endif /* __KEXEC_ZLIB_H */
> > diff --git a/kexec/zlib.c b/kexec/zlib.c
> > index 95b608059d41..34d5ca566769 100644
> > --- a/kexec/zlib.c
> > +++ b/kexec/zlib.c
> > @@ -23,6 +23,32 @@ static void _gzerror(gzFile fp, int *errnum, const char **errmsg)
> >       }
> >  }
> >
> > +int is_zlib_file(const char *filename, off_t *r_size)
> > +{
> > +     gzFile fp;
> > +     int errnum;
> > +     const char *msg;
> > +
> > +     if (!filename)
> > +             goto out;
> > +
> > +     fp = gzopen(filename, "rb");
>
> Does fp need to be closed somewhere to avoid a leak?

Right. Will fix this in v2.

v2 will be soon on its way.

Thanks,
Bhupesh

> > +     if (fp == 0) {
> > +             _gzerror(fp, &errnum, &msg);
> > +             dbgprintf("Cannot open `%s': %s\n", filename, msg);
> > +             goto out;
> > +     }
> > +
> > +     if (gzdirect(fp))
> > +             /* It's not in gzip format */
> > +             goto out;
> > +
> > +     /* It's in gzip format */
> > +     return 1;
> > +out:
> > +     return 0;
> > +}
> > +
> >  char *zlib_decompress_file(const char *filename, off_t *r_size)
> >  {
> >       gzFile fp;
> > @@ -84,6 +110,12 @@ fail:
> >       return buf;
> >  }
> >  #else
> > +
> > +int is_zlib_file(const char *filename, off_t *r_size)
> > +{
> > +     return 0;
> > +}
> > +
> >  char *zlib_decompress_file(const char *UNUSED(filename), off_t *UNUSED(r_size))
> >  {
> >       return NULL;
> > --
> > 2.7.4
> >



More information about the kexec mailing list