netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: "Köry Maincent" <kory.maincent@bootlin.com>
Cc: Michal Kubecek <mkubecek@suse.cz>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Maxime Chevallier <maxime.chevallier@bootlin.com>,
	stable@vger.kernel.org, thomas.petazzoni@bootlin.com,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH net 1/1] ethtool: Fix mod state of verbose no_mask bitset
Date: Thu, 5 Oct 2023 15:36:33 +0200	[thread overview]
Message-ID: <ZR674ase11YwjvsG@kernel.org> (raw)
In-Reply-To: <20231005100349.113f3bf1@kmaincent-XPS-13-7390>

On Thu, Oct 05, 2023 at 10:03:49AM +0200, Köry Maincent wrote:
> Hello Simon,
> 
> Thank for your review.
> 
> On Wed, 4 Oct 2023 13:07:14 +0200
> Simon Horman <horms@kernel.org> wrote:
> 
> > On Tue, Oct 03, 2023 at 10:56:52AM +0200, Köry Maincent wrote:
> > > From: Kory Maincent <kory.maincent@bootlin.com>
> >
> > > @@ -448,8 +450,11 @@ ethnl_update_bitset32_verbose(u32 *bitmap, unsigned
> > > int nbits, }
> > >  
> > >  	no_mask = tb[ETHTOOL_A_BITSET_NOMASK];
> > > -	if (no_mask)
> > > -		ethnl_bitmap32_clear(bitmap, 0, nbits, mod);
> > > +	if (no_mask) {
> > > +		tmp = kcalloc(nbits, sizeof(u32), GFP_KERNEL);
> > > +		memcpy(tmp, bitmap, nbits);  
> > 
> > Hi Köry,
> > 
> > I'm no expert on etnhl bitmaps. But the above doesn't seem correct to me.
> > Given that sizeof(u32) == 4:
> > 
> > * The allocation is for nbits * 4 bytes
> > * The copy is for its for nbits bytes
> > * I believe that bitmap contains space for the value followed by a mask.
> >   So it seems to me the size of bitmap, in words, is
> >   DIV_ROUND_UP(nbits, 32) * 2
> >   And in bytes: DIV_ROUND_UP(nbits, 32) * 16
> >   But perhaps only half is needed if only the value part of tmp is used.
> > 
> > If I'm on the right track here I'd suggest helpers might be in order.
> 
> You are right I should use the same alloc as ethnl_update_bitset with tmp
> instead of bitmap32:
> 
>         u32 small_bitmap32[ETHNL_SMALL_BITMAP_WORDS];                      
>         u32 *bitmap32 = small_bitmap32; 
>         if (nbits > ETHNL_SMALL_BITMAP_BITS) {                             
>                 unsigned int dst_words = DIV_ROUND_UP(nbits, 32);          
>                                                                            
>                 bitmap32 = kmalloc_array(dst_words, sizeof(u32), GFP_KERNEL);
>                 if (!bitmap32)                                             
>                         return -ENOMEM;                                    
>         }   
> 
> But I am still wondering if it needs to be double as you said for the size of
> the value followed by the mask. Not sure about it, as ethnl_update_bitset does
> not do it. 

If you only need the value, then I don' think you need to x2 the allocation.
But I could be wrong.

      reply	other threads:[~2023-10-05 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03  8:56 [PATCH net 1/1] ethtool: Fix mod state of verbose no_mask bitset Köry Maincent
2023-10-04 11:07 ` Simon Horman
2023-10-05  8:03   ` Köry Maincent
2023-10-05 13:36     ` Simon Horman [this message]

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=ZR674ase11YwjvsG@kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kory.maincent@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /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).