Skip to contentSkip to conversation

sparc: add missing put_device()

PATCH In review [email protected] 4 participants 4 messages Jul 18, 2023 – Jul 19, 2023 1 message not in the archive SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 sparc: add missing put_device()

The of_find_device_by_node() takes a reference to the underlying device structure, we should release that reference.

./arch/sparc/kernel/of_device_common.c:36:1-7: ERROR: missing put_device; call of_find_device_by_node on line 30, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:50:1-7: ERROR: missing put_device; call of_find_device_by_node on line 42, but without a corresponding object release within this function.

---
 arch/sparc/kernel/of_device_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/sparc/kernel/of_device_common.c +2 -2
index 7851307de6d0..5e9847d0fbed 100644
@@ -33,8 +33,8 @@ int of_address_to_resource(struct device_node *node, int index,
     if (!op || index >= op->num_resources)
         return -EINVAL;
 
-    put_device(op->dev);
     memcpy(r, &op->archdata.resource[index], sizeof(*r));
+    put_device(op->dev);
     return 0;
 }
 EXPORT_SYMBOL_GPL(of_address_to_resource);
@@ -47,8 +47,8 @@ void __iomem *of_iomap(struct device_node *node, int index)
     if (!op || index >= op->num_resources)
         return NULL;
 
-    put_device(op->dev);
     r = &op->archdata.resource[index];
+    put_device(op->dev);
 
     return of_ioremap(r, 0, resource_size(r), (char *) r->name);
 }
Reviewed-by on v1 1/1
#2 lore raw

Hi Ray Sun,

Quoted 11 lines · On Tue, Jul 18, 2023 at 04:57:06PM +0800, [email protected] wrote:

The of_find_device_by_node() takes a reference to the underlying device structure, we should release that reference.

./arch/sparc/kernel/of_device_common.c:36:1-7: ERROR: missing put_device; call of_find_device_by_node on line 30, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:50:1-7: ERROR: missing put_device; call of_find_device_by_node on line 42, but without a corresponding object release within this function.

This patch looks OK.

The challenge is to find someone to process sparc patches as the current maintainer is busy with other stuff.
I suggest to find another subsystem with active maintenance as you may find a higher success rate there to get stuff applied.

And no, I am not in a position to take sparc patches. Too little time for this :-(

Sam

#3 lore raw
In reply to [email protected]
Quoted 42 lines · On Tue, 18 Jul 2023 at 11:10, <[email protected]> wrote:

The of_find_device_by_node() takes a reference to the underlying device structure, we should release that reference.

./arch/sparc/kernel/of_device_common.c:36:1-7: ERROR: missing put_device; call of_find_device_by_node on line 30, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:50:1-7: ERROR: missing put_device; call of_find_device_by_node on line 42, but without a corresponding object release within this function.

---
  arch/sparc/kernel/of_device_common.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/sparc/kernel/of_device_common.c +1 -1
index 7851307de6d0..5e9847d0fbed 100644
@@ -33,8 +33,8 @@ int of_address_to_resource(struct device_node *node,
 int index,
      if (!op || index >= op->num_resources)
          return -EINVAL;
 
-    put_device(op->dev);
      memcpy(r, &op->archdata.resource[index], sizeof(*r));
+    put_device(op->dev);
      return 0;
  }
  EXPORT_SYMBOL_GPL(of_address_to_resource);
arch/sparc/kernel/of_device_common.c +1 -1
@@ -47,8 +47,8 @@ void __iomem *of_iomap(struct device_node *node, int
 index)
      if (!op || index >= op->num_resources)
          return NULL;
 
-    put_device(op->dev);
      r = &op->archdata.resource[index];
+    put_device(op->dev);
 
      return of_ioremap(r, 0, resource_size(r), (char *) r->name);
Quoted 1 line
  }

Based on Dmitry Baryshkov earlier comment I am not sure if this is a safe fix. (And I am not fully knowledgable about the memory lifecycle here)

If it is so that the device can disappear after put_device, is it then safe to access a
pointer to that devices resource information when calling of_ioremap() ?

-
Kjetil Oftedal

#4 lore raw
Quoted 50 lines · Kjetil Oftedal
Quoted 42 lines · On Tue, 18 Jul 2023 at 11:10, <[email protected]> wrote:

The of_find_device_by_node() takes a reference to the underlying device structure, we should release that reference.

./arch/sparc/kernel/of_device_common.c:36:1-7: ERROR: missing put_device; call of_find_device_by_node on line 30, but without a corresponding object release within this function. ./arch/sparc/kernel/of_device_common.c:50:1-7: ERROR: missing put_device; call of_find_device_by_node on line 42, but without a corresponding object release within this function.

---
  arch/sparc/kernel/of_device_common.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/sparc/kernel/of_device_common.c +1 -1
index 7851307de6d0..5e9847d0fbed 100644
@@ -33,8 +33,8 @@ int of_address_to_resource(struct device_node *node,
 int index,
      if (!op || index >= op->num_resources)
          return -EINVAL;
 
-    put_device(op->dev);
      memcpy(r, &op->archdata.resource[index], sizeof(*r));
+    put_device(op->dev);
      return 0;
  }
  EXPORT_SYMBOL_GPL(of_address_to_resource);
arch/sparc/kernel/of_device_common.c +1 -1
@@ -47,8 +47,8 @@ void __iomem *of_iomap(struct device_node *node, int
 index)
      if (!op || index >= op->num_resources)
          return NULL;
 
-    put_device(op->dev);
      r = &op->archdata.resource[index];
+    put_device(op->dev);
 
      return of_ioremap(r, 0, resource_size(r), (char *) r->name);
Quoted 1 line
  }

Based on Dmitry Baryshkov earlier comment I am not sure if this is a safe fix. (And I am not fully knowledgable about the memory lifecycle here)

Quoted 3 lines

If it is so that the device can disappear after put_device, is it then safe to access a
pointer to that devices resource information when calling of_ioremap() ?

No, r, being a pointer to device's archdata, can also be gone.

Also, I'd note to Ran Sun, that sending an unversioned fix for a fix is frowned upon. Please send a proper versioned patch with the included changelog, etc.
I think I have already pointed you to Documentation/process/ files. Please read them carefully and follow them, otherwise your further patches can get ignored/NAKed.

Signature · 2 lines
With best wishes
Dmitry