From patchwork Mon Nov 6 21:57:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugene Syromiatnikov X-Patchwork-Id: 10044559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0195B6032D for ; Mon, 6 Nov 2017 21:56:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7F3C29B20 for ; Mon, 6 Nov 2017 21:56:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCB9729B5C; Mon, 6 Nov 2017 21:56:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 827D529B20 for ; Mon, 6 Nov 2017 21:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753457AbdKFV4Q (ORCPT ); Mon, 6 Nov 2017 16:56:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753452AbdKFV4P (ORCPT ); Mon, 6 Nov 2017 16:56:15 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CFF382106 for ; Mon, 6 Nov 2017 21:56:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6CFF382106 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=esyr@redhat.com Received: from asgard.redhat.com (unknown [10.43.17.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F2455D6A9; Mon, 6 Nov 2017 21:56:12 +0000 (UTC) Date: Mon, 6 Nov 2017 22:57:03 +0100 From: Eugene Syromiatnikov To: linux-modules@vger.kernel.org Cc: Yauheni Kaliuta Subject: [PATCH] libkmod: fix uninitialized variable usage warnings Message-ID: <20171106215703.GA24781@asgard.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 06 Nov 2017 21:56:15 +0000 (UTC) Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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; line = lookup_builtin_file(ctx, name);