From patchwork Sun Nov 29 16:47:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 11939219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE1ABC64E7C for ; Sun, 29 Nov 2020 16:49:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 467E92074B for ; Sun, 29 Nov 2020 16:49:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ms3aw4nK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728185AbgK2QtO (ORCPT ); Sun, 29 Nov 2020 11:49:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52932 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728188AbgK2QtO (ORCPT ); Sun, 29 Nov 2020 11:49:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606668468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Va0pzBP0WDRC54+jdQgx8b2/fG4XqgFxvXzJV2H9QVY=; b=Ms3aw4nKz5R8l15192I8DCKg7JDNPQdhD2lOO0DH1v6dXAfPbN9dOkOsO6mOGYkv+3g5xM 1qfSAZjtbgMOu2Me2TCkMYZyPLVhk8Ifgm1YP5SOQbaXbqyBMPiQh0XO1M2YU/2kaA53NF hySYq6OzJNbam1QroioS3l7YbhVuVEw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-IU4LhKG2NX-6Owplt1jxhA-1; Sun, 29 Nov 2020 11:47:44 -0500 X-MC-Unique: IU4LhKG2NX-6Owplt1jxhA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 692D71E7EF; Sun, 29 Nov 2020 16:47:43 +0000 (UTC) Received: from astarta.redhat.com (ovpn-112-95.ams2.redhat.com [10.36.112.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33ABE5D9D2; Sun, 29 Nov 2020 16:47:39 +0000 (UTC) From: Yauheni Kaliuta To: linux-modules@vger.kernel.org Cc: lucas.de.marchi@gmail.com, Yauheni Kaliuta Subject: [PATCH 1/3] libkmod: kmod_builtin_get_modinfo: free modinfo on error Date: Sun, 29 Nov 2020 18:47:35 +0200 Message-Id: <20201129164737.135866-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: The function allocates array but on building it if get_string() fails it returns the error leaving the array allocated. The caller does not care about it in error case either. Free it to fix memory leak. Signed-off-by: Yauheni Kaliuta --- libkmod/libkmod-builtin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c index aaec5ddb0609..fc9a37644261 100644 --- a/libkmod/libkmod-builtin.c +++ b/libkmod/libkmod-builtin.c @@ -314,6 +314,7 @@ ssize_t kmod_builtin_get_modinfo(struct kmod_ctx *ctx, const char *modname, offset = get_string(iter, pos, &line, &linesz); if (offset <= 0) { count = (offset) ? -errno : -EOF; + free(*modinfo); goto fail; } From patchwork Sun Nov 29 16:47:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 11939217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74C5BC3E8C5 for ; Sun, 29 Nov 2020 16:49:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4ABF20738 for ; Sun, 29 Nov 2020 16:49:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BsjWovAJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725830AbgK2QtO (ORCPT ); Sun, 29 Nov 2020 11:49:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33790 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728185AbgK2QtO (ORCPT ); Sun, 29 Nov 2020 11:49:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606668468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r7jjJ1AHwBKXNEmiRRaw0Cp3aUEEI2PWUr8JPXLueeI=; b=BsjWovAJTX+KsgOB5odGaHmQMb1Jf1MQMk0fWffclxjjmobm+79dosOJccNFhYJDGSS4G8 4nl95EN9lXn1oT7MTyyxrfwCgoIHqZ2Hvxks41Tv5XiqHKabxJqo6O+S1+tlqIzbap0PDr zB0UhRNyODsm5NS/i57Nvg9y/PoeNjM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-201-gTkq62nKOVWNF4cGzzJZ_w-1; Sun, 29 Nov 2020 11:47:45 -0500 X-MC-Unique: gTkq62nKOVWNF4cGzzJZ_w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D27DC802B49; Sun, 29 Nov 2020 16:47:44 +0000 (UTC) Received: from astarta.redhat.com (ovpn-112-95.ams2.redhat.com [10.36.112.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7E445D9D2; Sun, 29 Nov 2020 16:47:43 +0000 (UTC) From: Yauheni Kaliuta To: linux-modules@vger.kernel.org Cc: lucas.de.marchi@gmail.com, Yauheni Kaliuta Subject: [PATCH 2/3] depmod: output_builtin_alias_bin: free idx on error path Date: Sun, 29 Nov 2020 18:47:36 +0200 Message-Id: <20201129164737.135866-2-yauheni.kaliuta@redhat.com> In-Reply-To: <20201129164737.135866-1-yauheni.kaliuta@redhat.com> References: <20201129164737.135866-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: idx is allocated in the beginning but it's not freed if there is a failure after the allocation. Change the error path: return immediately if idx allocation fails and then free it in both success and error path at the end. Signed-off-by: Yauheni Kaliuta --- tools/depmod.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index 875e31480818..2c03dfe7dc28 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -2412,10 +2412,8 @@ static int output_builtin_alias_bin(struct depmod *depmod, FILE *out) return 0; idx = index_create(); - if (idx == NULL) { - ret = -ENOMEM; - goto fail; - } + if (idx == NULL) + return -ENOMEM; ret = kmod_module_get_builtin(depmod->ctx, &builtin); if (ret < 0) { @@ -2458,13 +2456,12 @@ static int output_builtin_alias_bin(struct depmod *depmod, FILE *out) if (count) index_write(idx, out); - - index_destroy(idx); - fail: if (builtin) kmod_module_unref_list(builtin); + index_destroy(idx); + return ret; } From patchwork Sun Nov 29 16:47:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 11939221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5DF0C64E8A for ; Sun, 29 Nov 2020 16:49:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E1CD20738 for ; Sun, 29 Nov 2020 16:49:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c49Nl4a7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728195AbgK2QtQ (ORCPT ); Sun, 29 Nov 2020 11:49:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24422 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728188AbgK2QtP (ORCPT ); Sun, 29 Nov 2020 11:49:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606668469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oipVqmKoJWodF1KvUjlY5GRHtnx3/hhLh7rCmoK6Vvw=; b=c49Nl4a7liPZONGvCQa1BtkhlhhjcmvDM+0o0BUCzZAdOX4zZrRzNCvn3wLWJESm3K8ZTL sbKmpY18+WBY/RrDKabhDdGFbLN+0to/hH8uQR1cYKDWRXVNT6F7NJESpn+CgaZcejz1k3 E8H7Y0YgdaMWj2AwrD2gINl4CWpu6Eg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-78tYFD0dMS28vI0U5JBpuA-1; Sun, 29 Nov 2020 11:47:47 -0500 X-MC-Unique: 78tYFD0dMS28vI0U5JBpuA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4896E1E7EC; Sun, 29 Nov 2020 16:47:46 +0000 (UTC) Received: from astarta.redhat.com (ovpn-112-95.ams2.redhat.com [10.36.112.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3DAE35D9D2; Sun, 29 Nov 2020 16:47:45 +0000 (UTC) From: Yauheni Kaliuta To: linux-modules@vger.kernel.org Cc: lucas.de.marchi@gmail.com, Yauheni Kaliuta Subject: [PATCH 3/3] libkmod: kmod_log_null: qualify ctx argument as const Date: Sun, 29 Nov 2020 18:47:37 +0200 Message-Id: <20201129164737.135866-3-yauheni.kaliuta@redhat.com> In-Reply-To: <20201129164737.135866-1-yauheni.kaliuta@redhat.com> References: <20201129164737.135866-1-yauheni.kaliuta@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: kmod_log_null() does not change ctx (does nothing). Fix warnings In file included from libkmod/libkmod-index.c:33: libkmod/libkmod-index.c: In function ‘index_mm_open’: libkmod/libkmod-index.c:757:6: warning: passing argument 1 of ‘kmod_log_null’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] 757 | DBG(ctx, "file=%s\n", filename); Signed-off-by: Yauheni Kaliuta --- libkmod/libkmod-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libkmod/libkmod-internal.h b/libkmod/libkmod-internal.h index b22ac2a5f89e..398af9ce756a 100644 --- a/libkmod/libkmod-internal.h +++ b/libkmod/libkmod-internal.h @@ -11,7 +11,7 @@ #include "libkmod.h" static _always_inline_ _printf_format_(2, 3) void - kmod_log_null(struct kmod_ctx *ctx, const char *format, ...) {} + kmod_log_null(const struct kmod_ctx *ctx, const char *format, ...) {} #define kmod_log_cond(ctx, prio, arg...) \ do { \