DPDK patches and discussions
 help / color / mirror / Atom feed
* [RESEND 0/2] dmadev: clean code for dmadev
@ 2024-10-12  9:17 Jie Hai
  2024-10-12  9:17 ` [RESEND 1/2] dmadev: fix potential null pointer access Jie Hai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jie Hai @ 2024-10-12  9:17 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit; +Cc: lihuisong, fengchengwen, haijie1

This patch set make clean codes for dmadev.

Chengwen Feng (2):
  dmadev: fix potential null pointer access
  dmadev: clean code for verify parameter

 lib/dmadev/rte_dmadev.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

-- 
2.22.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RESEND 1/2] dmadev: fix potential null pointer access
  2024-10-12  9:17 [RESEND 0/2] dmadev: clean code for dmadev Jie Hai
@ 2024-10-12  9:17 ` Jie Hai
  2024-10-12  9:17 ` [RESEND 2/2] dmadev: clean code for verify parameter Jie Hai
  2024-10-17 16:43 ` [RESEND 0/2] dmadev: clean code for dmadev Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Jie Hai @ 2024-10-12  9:17 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Chengwen Feng, Kevin Laatz,
	Bruce Richardson, Conor Walsh
  Cc: lihuisong, haijie1

From: Chengwen Feng <fengchengwen@huawei.com>

When rte_dma_vchan_status(dev_id, vchan, NULL) is called, a null pointer
access is triggered.
This patch adds the null pointer checker.

Fixes: 5e0f85912754 ("dmadev: add channel status check for testing use")
Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/dmadev/rte_dmadev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 845727210fab..60c3d8ebf68e 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -741,7 +741,7 @@ rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *
 {
 	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
 
-	if (!rte_dma_is_valid(dev_id))
+	if (!rte_dma_is_valid(dev_id) || status == NULL)
 		return -EINVAL;
 
 	if (vchan >= dev->data->dev_conf.nb_vchans) {
-- 
2.22.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RESEND 2/2] dmadev: clean code for verify parameter
  2024-10-12  9:17 [RESEND 0/2] dmadev: clean code for dmadev Jie Hai
  2024-10-12  9:17 ` [RESEND 1/2] dmadev: fix potential null pointer access Jie Hai
@ 2024-10-12  9:17 ` Jie Hai
  2024-10-17 16:43 ` [RESEND 0/2] dmadev: clean code for dmadev Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Jie Hai @ 2024-10-12  9:17 UTC (permalink / raw)
  To: dev, thomas, ferruh.yigit, Chengwen Feng, Kevin Laatz, Bruce Richardson
  Cc: lihuisong, haijie1

From: Chengwen Feng <fengchengwen@huawei.com>

Make sure to verify the 'dev_id' parameter before using them.
Note: there is no actual problem with the current code, but it is
recommended to clean it up.

Cc: stable@dpdk.org

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/dmadev/rte_dmadev.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index 60c3d8ebf68e..4ba3b9380c5f 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -436,11 +436,12 @@ rte_dma_count_avail(void)
 int
 rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
 {
-	const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	const struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id) || dev_info == NULL)
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (*dev->dev_ops->dev_info_get == NULL)
 		return -ENOTSUP;
@@ -462,12 +463,13 @@ rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info)
 int
 rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
 	struct rte_dma_info dev_info;
+	struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id) || dev_conf == NULL)
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (dev->data->dev_started != 0) {
 		RTE_DMA_LOG(ERR,
@@ -513,11 +515,12 @@ rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf)
 int
 rte_dma_start(int16_t dev_id)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id))
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (dev->data->dev_conf.nb_vchans == 0) {
 		RTE_DMA_LOG(ERR, "Device %d must be configured first", dev_id);
@@ -545,11 +548,12 @@ rte_dma_start(int16_t dev_id)
 int
 rte_dma_stop(int16_t dev_id)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id))
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (dev->data->dev_started == 0) {
 		RTE_DMA_LOG(WARNING, "Device %d already stopped", dev_id);
@@ -572,11 +576,12 @@ rte_dma_stop(int16_t dev_id)
 int
 rte_dma_close(int16_t dev_id)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id))
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	/* Device must be stopped before it can be closed */
 	if (dev->data->dev_started == 1) {
@@ -600,13 +605,14 @@ int
 rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
 		    const struct rte_dma_vchan_conf *conf)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
 	struct rte_dma_info dev_info;
 	bool src_is_dev, dst_is_dev;
+	struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id) || conf == NULL)
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (dev->data->dev_started != 0) {
 		RTE_DMA_LOG(ERR,
@@ -693,10 +699,11 @@ rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan,
 int
 rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
 {
-	const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	const struct rte_dma_dev *dev;
 
 	if (!rte_dma_is_valid(dev_id) || stats == NULL)
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (vchan >= dev->data->dev_conf.nb_vchans &&
 	    vchan != RTE_DMA_ALL_VCHAN) {
@@ -715,11 +722,12 @@ rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats)
 int
 rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	struct rte_dma_dev *dev;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id))
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (vchan >= dev->data->dev_conf.nb_vchans &&
 	    vchan != RTE_DMA_ALL_VCHAN) {
@@ -739,10 +747,11 @@ rte_dma_stats_reset(int16_t dev_id, uint16_t vchan)
 int
 rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status)
 {
-	struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	struct rte_dma_dev *dev;
 
 	if (!rte_dma_is_valid(dev_id) || status == NULL)
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	if (vchan >= dev->data->dev_conf.nb_vchans) {
 		RTE_DMA_LOG(ERR, "Device %u vchan %u out of range", dev_id, vchan);
@@ -804,12 +813,13 @@ dma_dump_capability(FILE *f, uint64_t dev_capa)
 int
 rte_dma_dump(int16_t dev_id, FILE *f)
 {
-	const struct rte_dma_dev *dev = &rte_dma_devices[dev_id];
+	const struct rte_dma_dev *dev;
 	struct rte_dma_info dev_info;
 	int ret;
 
 	if (!rte_dma_is_valid(dev_id) || f == NULL)
 		return -EINVAL;
+	dev = &rte_dma_devices[dev_id];
 
 	ret = rte_dma_info_get(dev_id, &dev_info);
 	if (ret != 0) {
-- 
2.22.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RESEND 0/2] dmadev: clean code for dmadev
  2024-10-12  9:17 [RESEND 0/2] dmadev: clean code for dmadev Jie Hai
  2024-10-12  9:17 ` [RESEND 1/2] dmadev: fix potential null pointer access Jie Hai
  2024-10-12  9:17 ` [RESEND 2/2] dmadev: clean code for verify parameter Jie Hai
@ 2024-10-17 16:43 ` Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2024-10-17 16:43 UTC (permalink / raw)
  To: fengchengwen, Jie Hai; +Cc: dev, ferruh.yigit, lihuisong

12/10/2024 11:17, Jie Hai:
> This patch set make clean codes for dmadev.
> 
> Chengwen Feng (2):
>   dmadev: fix potential null pointer access
>   dmadev: clean code for verify parameter

Series applied, thanks.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-17 16:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-12  9:17 [RESEND 0/2] dmadev: clean code for dmadev Jie Hai
2024-10-12  9:17 ` [RESEND 1/2] dmadev: fix potential null pointer access Jie Hai
2024-10-12  9:17 ` [RESEND 2/2] dmadev: clean code for verify parameter Jie Hai
2024-10-17 16:43 ` [RESEND 0/2] dmadev: clean code for dmadev Thomas Monjalon

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).