All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: "Jose M. Guisado Gomez" <guigom@riseup.net>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf-next 1/3] netfilter: nf_tables: add userdata support for nft_object
Date: Tue, 8 Sep 2020 12:42:25 +0200	[thread overview]
Message-ID: <20200908104225.GA14876@salvia> (raw)
In-Reply-To: <20200902091241.1379-2-guigom@riseup.net>

On Wed, Sep 02, 2020 at 11:12:39AM +0200, Jose M. Guisado Gomez wrote:
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index 6ccce2a2e715..55111aefd3db 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
[...]
> @@ -5954,32 +5957,48 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
>  	obj->key.name = nla_strdup(nla[NFTA_OBJ_NAME], GFP_KERNEL);
>  	if (!obj->key.name) {
>  		err = -ENOMEM;
> -		goto err2;
> +		goto err_strdup;
> +	}
> +
> +	if(nla[NFTA_OBJ_USERDATA]) {
> +		udlen = nla_len(nla[NFTA_OBJ_USERDATA]);
> +		obj->udata = kzalloc(udlen, GFP_KERNEL);
> +		if (obj->udata == NULL)
> +			goto err_userdata;
> +	} else {
> +		obj->udata = NULL;
> +	}
> +
> +	if (udlen) {
> +		nla_memcpy(obj->udata, nla[NFTA_OBJ_USERDATA], udlen);
> +		obj->udlen = udlen;
>  	}

Probably simplify this?

	if(nla[NFTA_OBJ_USERDATA]) {
		udlen = nla_len(nla[NFTA_OBJ_USERDATA]);
		obj->udata = kzalloc(udlen, GFP_KERNEL);
		if (obj->udata == NULL)
			goto err_userdata;

        	nla_memcpy(obj->udata, nla[NFTA_OBJ_USERDATA], udlen);
        	obj->udlen = udlen;
        }

obj is allocated via kzalloc(), so obj->udata is already guaranteed to
be initialized to NULL, no need for the 'else' side of the branch.

Thanks.

  reply	other threads:[~2020-09-08 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02  9:12 [PATCH 0/3] add object userdata and comment support Jose M. Guisado Gomez
2020-09-02  9:12 ` [PATCH nf-next 1/3] netfilter: nf_tables: add userdata support for nft_object Jose M. Guisado Gomez
2020-09-08 10:42   ` Pablo Neira Ayuso [this message]
2020-09-08 11:01     ` [PATCH nf-next 1/3, v2] " Jose M. Guisado Gomez
2020-09-08 14:36       ` Pablo Neira Ayuso
2020-09-02  9:12 ` [PATCH libnftnl 2/3] object: add userdata and comment support Jose M. Guisado Gomez
2020-09-08 14:52   ` Pablo Neira Ayuso
2020-09-02  9:12 ` [PATCH nftables 3/3] src: add comment support for objects Jose M. Guisado Gomez
2020-09-03  9:16   ` [PATCH nftables 3/3, v2] " Jose M. Guisado Gomez
2020-09-08 14:53   ` [PATCH nftables 3/3] " Pablo Neira Ayuso

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=20200908104225.GA14876@salvia \
    --to=pablo@netfilter.org \
    --cc=guigom@riseup.net \
    --cc=netfilter-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.