From patchwork Wed Oct 14 16:49:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 1382262 X-Patchwork-Delegate: mkubecek@suse.cz Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CBJLC5ZTjz9sTL for ; Thu, 15 Oct 2020 03:49:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731343AbgJNQty (ORCPT ); Wed, 14 Oct 2020 12:49:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:49424 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727440AbgJNQty (ORCPT ); Wed, 14 Oct 2020 12:49:54 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1161FAAB2; Wed, 14 Oct 2020 16:49:53 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id CC0C860731; Wed, 14 Oct 2020 18:49:52 +0200 (CEST) From: Michal Kubecek Subject: [PATCH ethtool] netlink: fix allocation failure handling in dump_features() To: netdev@vger.kernel.org Cc: ivecera@redhat.com Message-Id: <20201014164952.CC0C860731@lion.mk-sys.cz> Date: Wed, 14 Oct 2020 18:49:52 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On allocation failure, dump_features() would set ret to -ENOMEM but then return 0 anyway. As there is nothing to free in this case anyway, the easiest fix is to simply return -ENOMEM rather than jumping to out_free label - which can be dropped as well as this was its only use. Fixes: f2c17e107900 ("netlink: add netlink handler for gfeatures (-k)") Reported-by: Ivan Vecera Signed-off-by: Michal Kubecek --- netlink/features.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/netlink/features.c b/netlink/features.c index 3f1240437350..2a0899e6eb04 100644 --- a/netlink/features.c +++ b/netlink/features.c @@ -117,11 +117,9 @@ int dump_features(const struct nlattr *const *tb, ret = prepare_feature_results(tb, &results); if (ret < 0) return -EFAULT; - - ret = -ENOMEM; feature_flags = calloc(results.count, sizeof(feature_flags[0])); if (!feature_flags) - goto out_free; + return -ENOMEM; /* map netdev features to legacy flags */ for (i = 0; i < results.count; i++) { @@ -182,7 +180,6 @@ int dump_features(const struct nlattr *const *tb, dump_feature(&results, NULL, NULL, i, name, ""); } -out_free: free(feature_flags); return 0; }