Re: [PATCH RFC net-next v2 05/18] net: pse-pd: Add support for PSE device index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 31 Oct 2024 22:28:29 +0100
Andrew Lunn <andrew@xxxxxxx> wrote:

> On Thu, Oct 31, 2024 at 07:27:59AM +0100, Oleksij Rempel wrote:
> > On Wed, Oct 30, 2024 at 05:53:07PM +0100, Kory Maincent wrote:
> > 
> > ...  
> > >  /**
> > >   * struct pse_control - a PSE control
> > > @@ -440,18 +441,22 @@ int pse_controller_register(struct
> > > pse_controller_dev *pcdev) 
> > >  	mutex_init(&pcdev->lock);
> > >  	INIT_LIST_HEAD(&pcdev->pse_control_head);
> > > +	ret = ida_alloc_max(&pse_ida, INT_MAX, GFP_KERNEL);  
> > 
> > s/INT_MAX/U32_MAX  
> 
>  * Return: The allocated ID, or %-ENOMEM if memory could not be allocated,
>  * or %-ENOSPC if there are no free IDs.
> 
> static inline int ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp)
> 
> We need to be careful here, at least theoretically. Assuming a 32 bit
> system, and you pass it U32_MAX, how does it return values in the
> range S32_MAX..U32_MAX when it also needs to be able to return
> negative numbers as errors?
> 
> I think the correct value to pass is S32_MAX, because it will always
> fit in a u32, and there is space left for negative values for errors.
> 
> But this is probably theoretical, no real system should have that many
> controllers.

Indeed you are right we might have issue between S32_MAX and U32_MAX if we want
to return errors.
Small question, is S32_MAX better than INT_MAX? Is there a point to limit it to
32 bits?

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux