linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eugene Syromiatnikov <esyr@redhat.com>
To: Lucas De Marchi <lucas.de.marchi@gmail.com>
Cc: linux-modules <linux-modules@vger.kernel.org>,
	Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Subject: Re: [PATCH] libkmod: fix uninitialized variable usage warnings
Date: Tue, 7 Nov 2017 12:59:38 +0100	[thread overview]
Message-ID: <20171107115938.GA19236@asgard.redhat.com> (raw)
In-Reply-To: <CAKi4VA+Q_WRsSyA-7uffSXRf+N7rz1_VSuMmqpQXMrT+bxgOBw@mail.gmail.com>

On Mon, Nov 06, 2017 at 07:24:55PM -0800, Lucas De Marchi wrote:
> On Mon, Nov 6, 2017 at 1:57 PM, Eugene Syromiatnikov <esyr@redhat.com> wrote:
> > There are two places where _cleanup_free_ variables are not initialised
> > by the time function exits that have been caught by gcc:
> >
> >         In file included from libkmod/libkmod.c:35:0:
> >         libkmod/libkmod.c: In function 'kmod_lookup_alias_is_builtin':
> >         ./shared/util.h:73:13: warning: 'line' may be used uninitialized in this function [-Wmaybe-uninitialized]
> >                  free(*(void**) p);
> >                      ^
> >         libkmod/libkmod.c:551:23: note: 'line' was declared here
> >           _cleanup_free_ char *line;
> >                                ^
> >         In file included from libkmod/libkmod-module.c:42:0:
> >         libkmod/libkmod-module.c: In function 'kmod_module_probe_insert_module':
> >         ./shared/util.h:73:13: warning: 'cmd' may be used uninitialized in this function [-Wmaybe-uninitialized]
> >                  free(*(void**) p);
> >                      ^
> >         libkmod/libkmod-module.c:996:23: note: 'cmd' was declared here
> >           _cleanup_free_ char *cmd;
> >                        ^
> >
> > This patch initializes them to NULL so free become no-op in these cases.
> > ---
> >  libkmod/libkmod-module.c | 2 +-
> >  libkmod/libkmod.c        | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
> > index 0a3ef11..6f23c1a 100644
> > --- a/libkmod/libkmod-module.c
> > +++ b/libkmod/libkmod-module.c
> > @@ -995,7 +995,7 @@ static int module_do_install_commands(struct kmod_module *mod,
> >  {
> >         const char *command = kmod_module_get_install_commands(mod);
> >         char *p;
> > -       _cleanup_free_ char *cmd;
> > +       _cleanup_free_ char *cmd = NULL;
> >         int err;
> >         size_t cmdlen, options_len, varlen;
> >
> > diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
> > index 69fe431..964772d 100644
> > --- a/libkmod/libkmod.c
> > +++ b/libkmod/libkmod.c
> > @@ -556,7 +556,7 @@ finish:
> >
> >  bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name)
> >  {
> > -       _cleanup_free_ char *line;
> > +       _cleanup_free_ char *line = NULL;
> 
> This seems to be a bogus warning. See the line just below... there's
> no way to exit this function without first  assigning 'line'.

In this instance, I initially thought that gcc is smart and derives
"uninitialised variable" from the lookup_builtin_file call, but nope, it
was happy only after line was initialised on declaration. On the other
hand, documentation[1] mentions that cleanup function is also called
during stack unwinding in case -fexceptions is enabled, and RHEL's RPM
package indeed has this flag, at least, so this GCC's complaint still
seems relevant.

[1] https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

> Lucas De Marchi

  reply	other threads:[~2017-11-07 11:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-06 21:57 [PATCH] libkmod: fix uninitialized variable usage warnings Eugene Syromiatnikov
2017-11-07  3:24 ` Lucas De Marchi
2017-11-07 11:59   ` Eugene Syromiatnikov [this message]
2017-11-07 16:45     ` Lucas De Marchi

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=20171107115938.GA19236@asgard.redhat.com \
    --to=esyr@redhat.com \
    --cc=linux-modules@vger.kernel.org \
    --cc=lucas.de.marchi@gmail.com \
    --cc=yauheni.kaliuta@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).