* [PATCH] compressdev: fix device ID validation check @ 2025-10-08 7:45 ashishg 2025-10-08 8:20 ` [EXTERNAL] " Akhil Goyal 2025-10-08 9:59 ` [PATCH v2] compressdev: update " ashishg 0 siblings, 2 replies; 3+ messages in thread From: ashishg @ 2025-10-08 7:45 UTC (permalink / raw) To: dev; +Cc: fanzhang.oss, Ashish Gupta From: Ashish Gupta <ashishg@marvell.com> nb_devs is incremented / decremented each time a compressdev is created/released. However, releasing device 1 incorrectly make device N invalid and inaccessible. Similarly when first half of the devices are released, rest half of the devices become inaccessible. This patch updates the validation check to ensure correct behavior. Signed-off-by: Ashish Gupta <ashishg@marvell.com> --- lib/compressdev/rte_compressdev.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/compressdev/rte_compressdev.c b/lib/compressdev/rte_compressdev.c index 33de3f511b..8435bfa134 100644 --- a/lib/compressdev/rte_compressdev.c +++ b/lib/compressdev/rte_compressdev.c @@ -104,12 +104,22 @@ rte_compressdev_pmd_get_named_dev(const char *name) return NULL; } +static inline uint8_t +rte_compressdev_is_valid_device_data(uint8_t dev_id) +{ + if (dev_id >= RTE_COMPRESS_MAX_DEVS || + compressdev_globals.devs[dev_id].data == NULL) + return 0; + + return 1; +} + static unsigned int rte_compressdev_is_valid_dev(uint8_t dev_id) { struct rte_compressdev *dev = NULL; - if (dev_id >= compressdev_globals.nb_devs) + if (!rte_compressdev_is_valid_device_data(dev_id)) return 0; dev = rte_compressdev_get_dev(dev_id); -- 2.43.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [EXTERNAL] [PATCH] compressdev: fix device ID validation check 2025-10-08 7:45 [PATCH] compressdev: fix device ID validation check ashishg @ 2025-10-08 8:20 ` Akhil Goyal 2025-10-08 9:59 ` [PATCH v2] compressdev: update " ashishg 1 sibling, 0 replies; 3+ messages in thread From: Akhil Goyal @ 2025-10-08 8:20 UTC (permalink / raw) To: Ashish Gupta, dev; +Cc: fanzhang.oss, Ashish Gupta > From: Ashish Gupta <ashishg@marvell.com> > > nb_devs is incremented / decremented each time a compressdev is > created/released. However, releasing device 1 incorrectly make device > N invalid and inaccessible. Similarly when first half of the devices > are released, rest half of the devices become inaccessible. This patch > updates the validation check to ensure correct behavior. Can you add fixes tag and cc stable@dpdk.org > > Signed-off-by: Ashish Gupta <ashishg@marvell.com> > --- > lib/compressdev/rte_compressdev.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/lib/compressdev/rte_compressdev.c > b/lib/compressdev/rte_compressdev.c > index 33de3f511b..8435bfa134 100644 > --- a/lib/compressdev/rte_compressdev.c > +++ b/lib/compressdev/rte_compressdev.c > @@ -104,12 +104,22 @@ rte_compressdev_pmd_get_named_dev(const char > *name) > return NULL; > } > > +static inline uint8_t > +rte_compressdev_is_valid_device_data(uint8_t dev_id) > +{ > + if (dev_id >= RTE_COMPRESS_MAX_DEVS || > + compressdev_globals.devs[dev_id].data == NULL) > + return 0; > + > + return 1; > +} > + > static unsigned int > rte_compressdev_is_valid_dev(uint8_t dev_id) > { > struct rte_compressdev *dev = NULL; > > - if (dev_id >= compressdev_globals.nb_devs) > + if (!rte_compressdev_is_valid_device_data(dev_id)) > return 0; > > dev = rte_compressdev_get_dev(dev_id); > -- > 2.43.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] compressdev: update device ID validation check 2025-10-08 7:45 [PATCH] compressdev: fix device ID validation check ashishg 2025-10-08 8:20 ` [EXTERNAL] " Akhil Goyal @ 2025-10-08 9:59 ` ashishg 1 sibling, 0 replies; 3+ messages in thread From: ashishg @ 2025-10-08 9:59 UTC (permalink / raw) To: dev; +Cc: stable, fanzhang.oss, Ashish Gupta From: Ashish Gupta <ashishg@marvell.com> nb_devs is incremented / decremented each time a compressdev is created/released. However, releasing device 1 incorrectly make device N invalid and inaccessible. Similarly when first half of the devices are released, rest half of the devices become inaccessible. This patch updates the validation check to ensure correct behavior. Signed-off-by: Ashish Gupta <ashishg@marvell.com> --- v2 * additional updates * updated commit message --- --- lib/compressdev/rte_compressdev.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/compressdev/rte_compressdev.c b/lib/compressdev/rte_compressdev.c index 33de3f511b..790b2cd658 100644 --- a/lib/compressdev/rte_compressdev.c +++ b/lib/compressdev/rte_compressdev.c @@ -30,6 +30,17 @@ static struct rte_compressdev_global compressdev_globals = { }; RTE_EXPORT_SYMBOL(rte_compressdev_capability_get) + +static inline uint8_t +rte_compressdev_is_valid_device_data(uint8_t dev_id) +{ + if (dev_id >= RTE_COMPRESS_MAX_DEVS || + compressdev_globals.devs[dev_id].data == NULL) + return 0; + + return 1; +} + const struct rte_compressdev_capabilities * rte_compressdev_capability_get(uint8_t dev_id, enum rte_comp_algorithm algo) @@ -38,10 +49,11 @@ rte_compressdev_capability_get(uint8_t dev_id, struct rte_compressdev_info dev_info; int i = 0; - if (dev_id >= compressdev_globals.nb_devs) { + if (!rte_compressdev_is_valid_device_data(dev_id)) { COMPRESSDEV_LOG(ERR, "Invalid dev_id=%d", dev_id); return NULL; } + rte_compressdev_info_get(dev_id, &dev_info); while ((capability = &dev_info.capabilities[i++])->algo != @@ -109,7 +121,7 @@ rte_compressdev_is_valid_dev(uint8_t dev_id) { struct rte_compressdev *dev = NULL; - if (dev_id >= compressdev_globals.nb_devs) + if (!rte_compressdev_is_valid_device_data(dev_id)) return 0; dev = rte_compressdev_get_dev(dev_id); @@ -129,10 +141,10 @@ rte_compressdev_get_dev_id(const char *name) if (name == NULL) return -1; - for (i = 0; i < compressdev_globals.nb_devs; i++) - if ((strcmp(compressdev_globals.devs[i].data->name, name) - == 0) && - (compressdev_globals.devs[i].attached == + for (i = 0; i < compressdev_globals.max_devs; i++) + if (compressdev_globals.devs[i].data != NULL && + (strcmp(compressdev_globals.devs[i].data->name, name) == 0) + && (compressdev_globals.devs[i].attached == RTE_COMPRESSDEV_ATTACHED)) return i; @@ -663,7 +675,7 @@ rte_compressdev_info_get(uint8_t dev_id, struct rte_compressdev_info *dev_info) { struct rte_compressdev *dev; - if (dev_id >= compressdev_globals.nb_devs) { + if (!rte_compressdev_is_valid_device_data(dev_id)) { COMPRESSDEV_LOG(ERR, "Invalid dev_id=%d", dev_id); return; } -- 2.43.0 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-08 10:00 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-10-08 7:45 [PATCH] compressdev: fix device ID validation check ashishg 2025-10-08 8:20 ` [EXTERNAL] " Akhil Goyal 2025-10-08 9:59 ` [PATCH v2] compressdev: update " ashishg
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).