[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241105103326.0360641d@kmaincent-XPS-13-7390>
Date: Tue, 5 Nov 2024 10:33:26 +0100
From: Kory Maincent <kory.maincent@...tlin.com>
To: Andrew Lunn <andrew@...n.ch>
Cc: Oleksij Rempel <o.rempel@...gutronix.de>, "David S. Miller"
<davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski
<kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>, Jonathan Corbet
<corbet@....net>, Donald Hunter <donald.hunter@...il.com>, Rob Herring
<robh@...nel.org>, Andrew Lunn <andrew+netdev@...n.ch>, Simon Horman
<horms@...nel.org>, Heiner Kallweit <hkallweit1@...il.com>, Russell King
<linux@...linux.org.uk>, Liam Girdwood <lgirdwood@...il.com>, Mark Brown
<broonie@...nel.org>, Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
linux-doc@...r.kernel.org, Kyle Swenson <kyle.swenson@....tech>, Dent
Project <dentproject@...uxfoundation.org>, kernel@...gutronix.de, Maxime
Chevallier <maxime.chevallier@...tlin.com>
Subject: Re: [PATCH RFC net-next v2 05/18] net: pse-pd: Add support for PSE
device index
On Thu, 31 Oct 2024 22:28:29 +0100
Andrew Lunn <andrew@...n.ch> 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
Powered by blists - more mailing lists