All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Minor improvements for remoteproc_virtio
@ 2026-10-10 15:21 Francesco Valla
  2026-10-10 15:21 ` [PATCH 1/3] remoteproc: virtio: add vdev_to_rsc() helper Francesco Valla
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Francesco Valla @ 2026-10-10 15:21 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Francesco Valla

Hello,

while working on the v2 of [1] I noticed a couple of areas that can be
improved in remoteproc_virtio, without a real functional impact.
Nothing critical.

Thank you!

Regards,
Francesco

[1] https://lore.kernel.org/linux-remoteproc/20260916-remoteproc_virtio_map-v1-0-dac8c5eb4aa9@valla.it/

Signed-off-by: Francesco Valla <francesco@valla.it>
---
Francesco Valla (3):
      remoteproc: virtio: add vdev_to_rsc() helper
      remoteproc: virtio: replace kmemdup with kmemdup_array
      remoteproc: virtio: remove stray white space

 drivers/remoteproc/remoteproc_virtio.c | 61 +++++++++++++---------------------
 1 file changed, 24 insertions(+), 37 deletions(-)
---
base-commit: 3857c2fe5449541e24afc5efdb0f81a8a8f9a3a0
change-id: 20261010-remoteproc_rework-6a06eb95ea86

Best regards,
--  
Francesco Valla <francesco@valla.it>


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

* [PATCH 1/3] remoteproc: virtio: add vdev_to_rsc() helper
  2026-10-10 15:21 [PATCH 0/3] Minor improvements for remoteproc_virtio Francesco Valla
@ 2026-10-10 15:21 ` Francesco Valla
  2026-10-10 15:21 ` [PATCH 2/3] remoteproc: virtio: replace kmemdup with kmemdup_array Francesco Valla
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Francesco Valla @ 2026-10-10 15:21 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Francesco Valla

Instead of repeating the table+offset math in every function that needs
to access the resource linked to a vdev, add a simple helper function
for that to simplify the code a bit.

No functional changes.

Signed-off-by: Francesco Valla <francesco@valla.it>
---
 drivers/remoteproc/remoteproc_virtio.c | 54 +++++++++++++---------------------
 1 file changed, 20 insertions(+), 34 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index d5e9ff045a28..dcafdfa7eab6 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -61,6 +61,16 @@ static  struct rproc *vdev_to_rproc(struct virtio_device *vdev)
 	return rvdev->rproc;
 }
 
+static struct fw_rsc_vdev *vdev_to_rsc(struct virtio_device *vdev)
+{
+	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
+	struct fw_rsc_vdev *rsc;
+
+	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
+
+	return rsc;
+}
+
 /* kick the remote processor, and let it know which virtqueue to poke at */
 static bool rproc_virtio_notify(struct virtqueue *vq)
 {
@@ -107,10 +117,10 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
 {
 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
 	struct rproc *rproc = vdev_to_rproc(vdev);
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
 	struct device *dev = &rproc->dev;
 	struct rproc_mem_entry *mem;
 	struct rproc_vring *rvring;
-	struct fw_rsc_vdev *rsc;
 	struct virtqueue *vq;
 	void *addr;
 	int num, size;
@@ -157,7 +167,6 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
 	vq->priv = rvring;
 
 	/* Update vring in resource table */
-	rsc = (void *)rproc->table_ptr + rvdev->rsc_offset;
 	rsc->vring[id].da = mem->da;
 
 	return vq;
@@ -212,20 +221,14 @@ static int rproc_virtio_find_vqs(struct virtio_device *vdev, unsigned int nvqs,
 
 static u8 rproc_virtio_get_status(struct virtio_device *vdev)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
 
 	return rsc->status;
 }
 
 static void rproc_virtio_set_status(struct virtio_device *vdev, u8 status)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
 
 	rsc->status = status;
 	dev_dbg(&vdev->dev, "status: %d\n", status);
@@ -233,10 +236,7 @@ static void rproc_virtio_set_status(struct virtio_device *vdev, u8 status)
 
 static void rproc_virtio_reset(struct virtio_device *vdev)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
 
 	rsc->status = 0;
 	dev_dbg(&vdev->dev, "reset !\n");
@@ -245,10 +245,7 @@ static void rproc_virtio_reset(struct virtio_device *vdev)
 /* provide the vdev features as retrieved from the firmware */
 static u64 rproc_virtio_get_features(struct virtio_device *vdev)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
 
 	return rsc->dfeatures;
 }
@@ -265,10 +262,7 @@ static void rproc_transport_features(struct virtio_device *vdev)
 
 static int rproc_virtio_finalize_features(struct virtio_device *vdev)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
 
 	/* Give virtio_ring a chance to accept features */
 	vring_transport_features(vdev);
@@ -291,12 +285,8 @@ static int rproc_virtio_finalize_features(struct virtio_device *vdev)
 static void rproc_virtio_get(struct virtio_device *vdev, unsigned int offset,
 			     void *buf, unsigned int len)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-	void *cfg;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
-	cfg = &rsc->vring[rsc->num_of_vrings];
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
+	void *cfg = &rsc->vring[rsc->num_of_vrings];
 
 	if (offset + len > rsc->config_len || offset + len < len) {
 		dev_err(&vdev->dev, "rproc_virtio_get: access out of bounds\n");
@@ -309,12 +299,8 @@ static void rproc_virtio_get(struct virtio_device *vdev, unsigned int offset,
 static void rproc_virtio_set(struct virtio_device *vdev, unsigned int offset,
 			     const void *buf, unsigned int len)
 {
-	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
-	struct fw_rsc_vdev *rsc;
-	void *cfg;
-
-	rsc = (void *)rvdev->rproc->table_ptr + rvdev->rsc_offset;
-	cfg = &rsc->vring[rsc->num_of_vrings];
+	struct fw_rsc_vdev *rsc = vdev_to_rsc(vdev);
+	void *cfg = &rsc->vring[rsc->num_of_vrings];
 
 	if (offset + len > rsc->config_len || offset + len < len) {
 		dev_err(&vdev->dev, "rproc_virtio_set: access out of bounds\n");

-- 
2.56.0


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

* [PATCH 2/3] remoteproc: virtio: replace kmemdup with kmemdup_array
  2026-10-10 15:21 [PATCH 0/3] Minor improvements for remoteproc_virtio Francesco Valla
  2026-10-10 15:21 ` [PATCH 1/3] remoteproc: virtio: add vdev_to_rsc() helper Francesco Valla
@ 2026-10-10 15:21 ` Francesco Valla
  2026-10-10 15:21 ` [PATCH 3/3] remoteproc: virtio: remove stray white space Francesco Valla
  2026-10-13 16:36 ` [PATCH 0/3] Minor improvements for remoteproc_virtio Mathieu Poirier
  3 siblings, 0 replies; 5+ messages in thread
From: Francesco Valla @ 2026-10-10 15:21 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Francesco Valla

Let kmemdup_array take care of multiplication and overflows.

While at it, add blank lines in the same function for readability.

Signed-off-by: Francesco Valla <francesco@valla.it>
---
 drivers/remoteproc/remoteproc_virtio.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index dcafdfa7eab6..6db228a9f87a 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -37,11 +37,12 @@ static int copy_dma_range_map(struct device *to, struct device *from)
 	for (r = map; r->size; r++)
 		num_ranges++;
 
-	new_map = kmemdup(map, array_size(num_ranges + 1, sizeof(*map)),
-			  GFP_KERNEL);
+	new_map = kmemdup_array(map, num_ranges + 1, sizeof(*map), GFP_KERNEL);
 	if (!new_map)
 		return -ENOMEM;
+
 	to->dma_range_map = new_map;
+
 	return 0;
 }
 

-- 
2.56.0


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

* [PATCH 3/3] remoteproc: virtio: remove stray white space
  2026-10-10 15:21 [PATCH 0/3] Minor improvements for remoteproc_virtio Francesco Valla
  2026-10-10 15:21 ` [PATCH 1/3] remoteproc: virtio: add vdev_to_rsc() helper Francesco Valla
  2026-10-10 15:21 ` [PATCH 2/3] remoteproc: virtio: replace kmemdup with kmemdup_array Francesco Valla
@ 2026-10-10 15:21 ` Francesco Valla
  2026-10-13 16:36 ` [PATCH 0/3] Minor improvements for remoteproc_virtio Mathieu Poirier
  3 siblings, 0 replies; 5+ messages in thread
From: Francesco Valla @ 2026-10-10 15:21 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, Francesco Valla

Remove a stray white space in function definition. No functional
changes.

Signed-off-by: Francesco Valla <francesco@valla.it>
---
 drivers/remoteproc/remoteproc_virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index 6db228a9f87a..4ed47ccffa13 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -55,7 +55,7 @@ static struct rproc_vdev *vdev_to_rvdev(struct virtio_device *vdev)
 	return platform_get_drvdata(pdev);
 }
 
-static  struct rproc *vdev_to_rproc(struct virtio_device *vdev)
+static struct rproc *vdev_to_rproc(struct virtio_device *vdev)
 {
 	struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
 

-- 
2.56.0


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

* Re: [PATCH 0/3] Minor improvements for remoteproc_virtio
  2026-10-10 15:21 [PATCH 0/3] Minor improvements for remoteproc_virtio Francesco Valla
                   ` (2 preceding siblings ...)
  2026-10-10 15:21 ` [PATCH 3/3] remoteproc: virtio: remove stray white space Francesco Valla
@ 2026-10-13 16:36 ` Mathieu Poirier
  3 siblings, 0 replies; 5+ messages in thread
From: Mathieu Poirier @ 2026-10-13 16:36 UTC (permalink / raw)
  To: Francesco Valla; +Cc: Bjorn Andersson, linux-remoteproc, linux-kernel

On Sat, Oct 10, 2026 at 05:21:05PM +0200, Francesco Valla wrote:
> Hello,
> 
> while working on the v2 of [1] I noticed a couple of areas that can be
> improved in remoteproc_virtio, without a real functional impact.
> Nothing critical.
> 
> Thank you!
> 
> Regards,
> Francesco
> 
> [1] https://lore.kernel.org/linux-remoteproc/20260916-remoteproc_virtio_map-v1-0-dac8c5eb4aa9@valla.it/
> 
> Signed-off-by: Francesco Valla <francesco@valla.it>
> ---
> Francesco Valla (3):
>       remoteproc: virtio: add vdev_to_rsc() helper
>       remoteproc: virtio: replace kmemdup with kmemdup_array
>       remoteproc: virtio: remove stray white space
> 
>  drivers/remoteproc/remoteproc_virtio.c | 61 +++++++++++++---------------------
>  1 file changed, 24 insertions(+), 37 deletions(-)

I have applied this set.

Thanks,
Mathieu

> ---
> base-commit: 3857c2fe5449541e24afc5efdb0f81a8a8f9a3a0
> change-id: 20261010-remoteproc_rework-6a06eb95ea86
> 
> Best regards,
> --  
> Francesco Valla <francesco@valla.it>
> 

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

end of thread, other threads:[~2026-10-13 16:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-10 15:21 [PATCH 0/3] Minor improvements for remoteproc_virtio Francesco Valla
2026-10-10 15:21 ` [PATCH 1/3] remoteproc: virtio: add vdev_to_rsc() helper Francesco Valla
2026-10-10 15:21 ` [PATCH 2/3] remoteproc: virtio: replace kmemdup with kmemdup_array Francesco Valla
2026-10-10 15:21 ` [PATCH 3/3] remoteproc: virtio: remove stray white space Francesco Valla
2026-10-13 16:36 ` [PATCH 0/3] Minor improvements for remoteproc_virtio Mathieu Poirier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.