Skip to contentSkip to conversation

soc: ti: k3-ringacc: Add try_module_get() to k3_dmaring_request_dual_ring()

PATCH Superseded Nicolas Frayer 2 participants 3 messages Dec 21, 2022 – Dec 30, 2022 TI Keystone multicore navigator drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc: ti: k3-ringacc: Add try_module_get() to k3_dmaring_request_dual_ring()

When the k3 ring accelerator driver has been modified to add module build support, try_module_get() and module_put() have been added to update the module refcnt. One code path has not been updated and it has introduced an issue where the refcnt is decremented by module_put() in k3_ringacc_ring_free() without being incremented previously. Adding try_module_get() to k3_dmaring_request_dual_ring() ensures the refcnt is kept up to date.

---
 drivers/soc/ti/k3-ringacc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/soc/ti/k3-ringacc.c +7 -0
index e01e4d815230a..8f131368a7586 100644
@@ -406,6 +406,11 @@ static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id,
 
 	mutex_lock(&ringacc->req_lock);
 
+	if (!try_module_get(ringacc->dev->driver->owner)) {
+		ret = -EINVAL;
+		goto err_module_get;
+	}
+
 	if (test_bit(fwd_id, ringacc->rings_inuse)) {
 		ret = -EBUSY;
 		goto error;
@@ -421,6 +426,8 @@ static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id,
 	return 0;
 
 error:
+	module_put(ringacc->dev->driver->owner);
+err_module_get:
 	mutex_unlock(&ringacc->req_lock);
 	return ret;
 }
Signature · 7 lines
2.25.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 1/1
#1 lore raw

Hi Nicolas,

Quoted 7 lines · Nicolas Frayer

When the k3 ring accelerator driver has been modified to add module build support, try_module_get() and module_put() have been added to update the module refcnt. One code path has not been updated and it has introduced an issue where the refcnt is decremented by module_put() in k3_ringacc_ring_free() without being incremented previously. Adding try_module_get() to k3_dmaring_request_dual_ring() ensures the refcnt is kept up to date.

Good catch!
I had never had my hands on a device with DMSS (BCDMA/PKDMA) and the original module support was developed and tested on devices with UDMA.

can you add the fixes tag along with my reviewed by tag?

Fixes c07f216a8b72 ("soc: ti: k3-ringacc: Allow the driver to be built as module")
Quoted 31 lines
---
  drivers/soc/ti/k3-ringacc.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/soc/ti/k3-ringacc.c +7 -0
index e01e4d815230a..8f131368a7586 100644
@@ -406,6 +406,11 @@ static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id,
 
  	mutex_lock(&ringacc->req_lock);
 
+	if (!try_module_get(ringacc->dev->driver->owner)) {
+		ret = -EINVAL;
+		goto err_module_get;
+	}
+
  	if (test_bit(fwd_id, ringacc->rings_inuse)) {
  		ret = -EBUSY;
  		goto error;
@@ -421,6 +426,8 @@ static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id,
  	return 0;
 
  error:
+	module_put(ringacc->dev->driver->owner);
+err_module_get:
  	mutex_unlock(&ringacc->req_lock);
  	return ret;
  }
Signature · 1 line
Péter
#2 lore raw
Quoted 46 lines · Péter Ujfalusi

Hi Nicolas,

Quoted 7 lines · Nicolas Frayer

When the k3 ring accelerator driver has been modified to add module build support, try_module_get() and module_put() have been added to update the module refcnt. One code path has not been updated and it has introduced an issue where the refcnt is decremented by module_put() in k3_ringacc_ring_free() without being incremented previously. Adding try_module_get() to k3_dmaring_request_dual_ring() ensures the refcnt is kept up to date.

Good catch!
I had never had my hands on a device with DMSS (BCDMA/PKDMA) and the original module support was developed and tested on devices with UDMA.

can you add the fixes tag along with my reviewed by tag?

Fixes c07f216a8b72 ("soc: ti: k3-ringacc: Allow the driver to be built as module")
Quoted 25 lines
---
  drivers/soc/ti/k3-ringacc.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/soc/ti/k3-ringacc.c +5 -0
index e01e4d815230a..8f131368a7586 100644
@@ -406,6 +406,11 @@ static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id,
 
      mutex_lock(&ringacc->req_lock);
 
+     if (!try_module_get(ringacc->dev->driver->owner)) {
+             ret = -EINVAL;
+             goto err_module_get;
+     }
+
      if (test_bit(fwd_id, ringacc->rings_inuse)) {
              ret = -EBUSY;
              goto error;
@@ -421,6 +426,8 @@ static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id,
      return 0;
 
Quoted 9 lines

drivers/soc/ti/k3-ringacc.c static int k3_dmaring_request_dual_ring(struct k3_ringacc *ringacc, int fwd_id, · line 433

Quoted 6 lines
drivers/soc/ti/k3-ringacc.c +2 -0
  error:
+     module_put(ringacc->dev->driver->owner);
+err_module_get:
      mutex_unlock(&ringacc->req_lock);
      return ret;
  }

--
Péter

Thanks Peter, I'll send a v2 with the tags.