From: Ivan Vecera <ivecera@redhat.com>
To: netdev@vger.kernel.org
Cc: Michal Kubecek <mkubecek@suse.cz>
Subject: [PATCH ethtool 1/2] netlink: return -ENOMEM when calloc fails
Date: Thu, 24 Sep 2020 21:27:57 +0200 [thread overview]
Message-ID: <20200924192758.577595-1-ivecera@redhat.com> (raw)
Fixes: f2c17e107900 ("netlink: add netlink handler for gfeatures (-k)")
Cc: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
netlink/features.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/netlink/features.c b/netlink/features.c
index 3f1240437350..b2cf57eea660 100644
--- a/netlink/features.c
+++ b/netlink/features.c
@@ -112,16 +112,17 @@ int dump_features(const struct nlattr *const *tb,
unsigned int *feature_flags = NULL;
struct feature_results results;
unsigned int i, j;
- int ret;
+ int ret = 0;
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)
+ if (!feature_flags) {
+ ret = -ENOMEM;
goto out_free;
+ }
/* map netdev features to legacy flags */
for (i = 0; i < results.count; i++) {
@@ -184,7 +185,7 @@ int dump_features(const struct nlattr *const *tb,
out_free:
free(feature_flags);
- return 0;
+ return ret;
}
int features_reply_cb(const struct nlmsghdr *nlhdr, void *data)
--
2.26.2
next reply other threads:[~2020-09-24 19:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 19:27 Ivan Vecera [this message]
2020-09-24 19:27 ` [PATCH ethtool 2/2] netlink: fix memory leak Ivan Vecera
2020-09-28 15:37 ` Michal Kubecek
2020-09-28 15:44 ` [PATCH ethtool 1/2] netlink: return -ENOMEM when calloc fails Michal Kubecek
2020-09-28 19:21 ` Ivan Vecera
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=20200924192758.577595-1-ivecera@redhat.com \
--to=ivecera@redhat.com \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
/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).