* [PATCH v3 net-next] ptp: Move from simple ida to xarray
@ 2024-03-11 13:59 Kory Maincent
2024-03-11 14:17 ` Przemek Kitszel
0 siblings, 1 reply; 3+ messages in thread
From: Kory Maincent @ 2024-03-11 13:59 UTC (permalink / raw)
To: Jakub Kicinski, Simon Horman, Przemek Kitszel, netdev, linux-kernel
Cc: thomas.petazzoni, Richard Cochran
Move from simple ida to xarray for storing and loading the ptp_clock
pointer. This prepares support for future hardware timestamp selection by
being able to link the ptp clock index to its pointer.
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
Change in v2:
- Update an err value missing.
Change in v3:
- Refactor err management.
---
drivers/ptp/ptp_clock.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index 3aaf1a3430c5..8eebf1373ca3 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -31,7 +31,7 @@ struct class *ptp_class;
static dev_t ptp_devt;
-static DEFINE_IDA(ptp_clocks_map);
+static DEFINE_XARRAY_ALLOC(ptp_clocks_map);
/* time stamp event queue operations */
@@ -201,7 +201,7 @@ static void ptp_clock_release(struct device *dev)
bitmap_free(tsevq->mask);
kfree(tsevq);
debugfs_remove(ptp->debugfs_root);
- ida_free(&ptp_clocks_map, ptp->index);
+ xa_erase(&ptp_clocks_map, ptp->index);
kfree(ptp);
}
@@ -241,16 +241,16 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
return ERR_PTR(-EINVAL);
/* Initialize a clock structure. */
- err = -ENOMEM;
ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
- if (ptp == NULL)
+ if (!ptp) {
+ err = -ENOMEM;
goto no_memory;
+ }
- index = ida_alloc_max(&ptp_clocks_map, MINORMASK, GFP_KERNEL);
- if (index < 0) {
- err = index;
+ err = xa_alloc(&ptp_clocks_map, &index, ptp, xa_limit_31b,
+ GFP_KERNEL);
+ if (err)
goto no_slot;
- }
ptp->clock.ops = ptp_clock_ops;
ptp->info = info;
@@ -258,13 +258,17 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
ptp->index = index;
INIT_LIST_HEAD(&ptp->tsevqs);
queue = kzalloc(sizeof(*queue), GFP_KERNEL);
- if (!queue)
+ if (!queue) {
+ err = -ENOMEM;
goto no_memory_queue;
+ }
list_add_tail(&queue->qlist, &ptp->tsevqs);
spin_lock_init(&ptp->tsevqs_lock);
queue->mask = bitmap_alloc(PTP_MAX_CHANNELS, GFP_KERNEL);
- if (!queue->mask)
+ if (!queue->mask) {
+ err = -ENOMEM;
goto no_memory_bitmap;
+ }
bitmap_set(queue->mask, 0, PTP_MAX_CHANNELS);
spin_lock_init(&queue->lock);
mutex_init(&ptp->pincfg_mux);
@@ -378,7 +382,7 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
list_del(&queue->qlist);
kfree(queue);
no_memory_queue:
- ida_free(&ptp_clocks_map, index);
+ xa_erase(&ptp_clocks_map, index);
no_slot:
kfree(ptp);
no_memory:
@@ -511,7 +515,7 @@ static void __exit ptp_exit(void)
{
class_destroy(ptp_class);
unregister_chrdev_region(ptp_devt, MINORMASK + 1);
- ida_destroy(&ptp_clocks_map);
+ xa_destroy(&ptp_clocks_map);
}
static int __init ptp_init(void)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 net-next] ptp: Move from simple ida to xarray
2024-03-11 13:59 [PATCH v3 net-next] ptp: Move from simple ida to xarray Kory Maincent
@ 2024-03-11 14:17 ` Przemek Kitszel
2024-03-11 14:48 ` Köry Maincent
0 siblings, 1 reply; 3+ messages in thread
From: Przemek Kitszel @ 2024-03-11 14:17 UTC (permalink / raw)
To: Kory Maincent, Jakub Kicinski, Simon Horman, netdev, linux-kernel
Cc: thomas.petazzoni, Richard Cochran
On 3/11/24 14:59, Kory Maincent wrote:
> Move from simple ida to xarray for storing and loading the ptp_clock
> pointer. This prepares support for future hardware timestamp selection by
> being able to link the ptp clock index to its pointer.
>
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---
>
> Change in v2:
> - Update an err value missing.
>
> Change in v3:
> - Refactor err management.
> ---
> drivers/ptp/ptp_clock.c | 28 ++++++++++++++++------------
> 1 file changed, 16 insertions(+), 12 deletions(-)
>
sorry for not commenting more on v2 :/
As you change (the intent of*) underlying data structure you should also
change included header file.
*ida is an xarray wrapper by now so the change is on semantic level only
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index 3aaf1a3430c5..8eebf1373ca3 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -31,7 +31,7 @@ struct class *ptp_class;
>
> static dev_t ptp_devt;
>
> -static DEFINE_IDA(ptp_clocks_map);
> +static DEFINE_XARRAY_ALLOC(ptp_clocks_map);
>
> /* time stamp event queue operations */
>
> @@ -201,7 +201,7 @@ static void ptp_clock_release(struct device *dev)
> bitmap_free(tsevq->mask);
> kfree(tsevq);
> debugfs_remove(ptp->debugfs_root);
> - ida_free(&ptp_clocks_map, ptp->index);
> + xa_erase(&ptp_clocks_map, ptp->index);
> kfree(ptp);
> }
>
> @@ -241,16 +241,16 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
> return ERR_PTR(-EINVAL);
>
> /* Initialize a clock structure. */
> - err = -ENOMEM;
you could remove 0-init of err in this commit too
> ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL);
> - if (ptp == NULL)
> + if (!ptp) {
> + err = -ENOMEM;
> goto no_memory;
> + }
>
[snip]
Thanks a lot!
Only nitpicks left, so:
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 net-next] ptp: Move from simple ida to xarray
2024-03-11 14:17 ` Przemek Kitszel
@ 2024-03-11 14:48 ` Köry Maincent
0 siblings, 0 replies; 3+ messages in thread
From: Köry Maincent @ 2024-03-11 14:48 UTC (permalink / raw)
To: Przemek Kitszel
Cc: Jakub Kicinski, Simon Horman, netdev, linux-kernel,
thomas.petazzoni, Richard Cochran
On Mon, 11 Mar 2024 15:17:15 +0100
Przemek Kitszel <przemyslaw.kitszel@intel.com> wrote:
> On 3/11/24 14:59, Kory Maincent wrote:
> > Move from simple ida to xarray for storing and loading the ptp_clock
> > pointer. This prepares support for future hardware timestamp selection by
> > being able to link the ptp clock index to its pointer.
> >
> > Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> > ---
> >
> > Change in v2:
> > - Update an err value missing.
> >
> > Change in v3:
> > - Refactor err management.
> > ---
> > drivers/ptp/ptp_clock.c | 28 ++++++++++++++++------------
> > 1 file changed, 16 insertions(+), 12 deletions(-)
> >
>
> sorry for not commenting more on v2 :/
No worry, thanks for your review!!
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-11 14:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 13:59 [PATCH v3 net-next] ptp: Move from simple ida to xarray Kory Maincent
2024-03-11 14:17 ` Przemek Kitszel
2024-03-11 14:48 ` Köry Maincent
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).