2012-10-11 05:19:51

by Yasuaki Ishimatsu

[permalink] [raw]
Subject: [PATCH v2 0/2] Suppress "Device <device name> does not have a release() function" warning

This patch-set is patches to which [1] and [2] are updated
[1] memory-hotplug: add memory_block_release
[2] memory-hotplug: add node_device_release
from following patch-set.

https://lkml.org/lkml/2012/9/27/39

So the patch-set version is v2.

v1 -> v2
[PATCH 1/2]
- change subject to Suppress "Device memoryX does not have a release()
function" warning.
- Add detail information into description
- change function name from release_memory_block() to memory_block_release(),
because other device release() function is named to <device_name>_release()
[PATCH 2/2]
- change subject to Suppress "Device nodeX does not have a release() function"
warning.
- Add detail information into description
- Remove memset() to initialize a node struct from node_device_release()
- Add memset() to initialize a node struct into register_node()


2012-10-11 05:22:53

by Yasuaki Ishimatsu

[permalink] [raw]
Subject: [PATCH 1/2]suppress "Device memoryX does not have a release() function" warning

When calling remove_memory_block(), the function shows following message at
device_release().

"Device 'memory528' does not have a release() function, it is broken and must
be fixed."

The reason is memory_block's device struct does not have a release() function.

So the patch registers memory_block_release() to the device's release() function
for suppressing the warning message. Additionally, the patch moves kfree(mem)
into the release function since the release function is prepared as a means
to free a memory_block struct.

CC: David Rientjes <[email protected]>
CC: Jiang Liu <[email protected]>
Cc: Minchan Kim <[email protected]>
CC: Andrew Morton <[email protected]>
CC: KOSAKI Motohiro <[email protected]>
CC: Wen Congyang <[email protected]>
Signed-off-by: Yasuaki Ishimatsu <[email protected]>
---
drivers/base/memory.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

Index: linux-3.6/drivers/base/memory.c
===================================================================
--- linux-3.6.orig/drivers/base/memory.c 2012-10-11 11:37:33.404668048 +0900
+++ linux-3.6/drivers/base/memory.c 2012-10-11 11:38:27.865672989 +0900
@@ -70,6 +70,13 @@ void unregister_memory_isolate_notifier(
}
EXPORT_SYMBOL(unregister_memory_isolate_notifier);

+static void memory_block_release(struct device *dev)
+{
+ struct memory_block *mem = container_of(dev, struct memory_block, dev);
+
+ kfree(mem);
+}
+
/*
* register_memory - Setup a sysfs device for a memory block
*/
@@ -80,6 +87,7 @@ int register_memory(struct memory_block

memory->dev.bus = &memory_subsys;
memory->dev.id = memory->start_section_nr / sections_per_block;
+ memory->dev.release = memory_block_release;

error = device_register(&memory->dev);
return error;
@@ -630,7 +638,6 @@ int remove_memory_block(unsigned long no
mem_remove_simple_file(mem, phys_device);
mem_remove_simple_file(mem, removable);
unregister_memory(mem);
- kfree(mem);
} else
kobject_put(&mem->dev.kobj);

2012-10-11 05:27:12

by Yasuaki Ishimatsu

[permalink] [raw]
Subject: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

When calling unregister_node(), the function shows following message at
device_release().

"Device 'node2' does not have a release() function, it is broken and must
be fixed."

The reason is node's device struct does not have a release() function.

So the patch registers node_device_release() to the device's release()
function for suppressing the warning message. Additionally, the patch adds
memset() to initialize a node struct into register_node(). Because the node
struct is part of node_devices[] array and it cannot be freed by
node_device_release(). So if system reuses the node struct, it has a garbage.

CC: David Rientjes <[email protected]>
CC: Jiang Liu <[email protected]>
Cc: Minchan Kim <[email protected]>
CC: Andrew Morton <[email protected]>
CC: KOSAKI Motohiro <[email protected]>
Signed-off-by: Yasuaki Ishimatsu <[email protected]>
Signed-off-by: Wen Congyang <[email protected]>
---
drivers/base/node.c | 11 +++++++++++
1 file changed, 11 insertions(+)

Index: linux-3.6/drivers/base/node.c
===================================================================
--- linux-3.6.orig/drivers/base/node.c 2012-10-11 10:04:02.149758748 +0900
+++ linux-3.6/drivers/base/node.c 2012-10-11 10:20:34.111806931 +0900
@@ -252,6 +252,14 @@ static inline void hugetlb_register_node
static inline void hugetlb_unregister_node(struct node *node) {}
#endif

+static void node_device_release(struct device *dev)
+{
+#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
+ struct node *node_dev = to_node(dev);
+
+ flush_work(&node_dev->node_work);
+#endif
+}

/*
* register_node - Setup a sysfs device for a node.
@@ -263,8 +271,11 @@ int register_node(struct node *node, int
{
int error;

+ memset(node, 0, sizeof(*node));
+
node->dev.id = num;
node->dev.bus = &node_subsys;
+ node->dev.release = node_device_release;
error = device_register(&node->dev);

if (!error){

2012-10-11 20:23:53

by David Rientjes

[permalink] [raw]
Subject: Re: [PATCH 1/2]suppress "Device memoryX does not have a release() function" warning

On Thu, 11 Oct 2012, Yasuaki Ishimatsu wrote:

> When calling remove_memory_block(), the function shows following message at
> device_release().
>
> "Device 'memory528' does not have a release() function, it is broken and must
> be fixed."
>
> The reason is memory_block's device struct does not have a release() function.
>
> So the patch registers memory_block_release() to the device's release() function
> for suppressing the warning message. Additionally, the patch moves kfree(mem)
> into the release function since the release function is prepared as a means
> to free a memory_block struct.
>
> CC: David Rientjes <[email protected]>
> CC: Jiang Liu <[email protected]>
> Cc: Minchan Kim <[email protected]>
> CC: Andrew Morton <[email protected]>
> CC: KOSAKI Motohiro <[email protected]>
> CC: Wen Congyang <[email protected]>
> Signed-off-by: Yasuaki Ishimatsu <[email protected]>

Acked-by: David Rientjes <[email protected]>

2012-10-11 20:32:02

by David Rientjes

[permalink] [raw]
Subject: Re: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

On Thu, 11 Oct 2012, Yasuaki Ishimatsu wrote:

> When calling unregister_node(), the function shows following message at
> device_release().
>
> "Device 'node2' does not have a release() function, it is broken and must
> be fixed."
>
> The reason is node's device struct does not have a release() function.
>
> So the patch registers node_device_release() to the device's release()
> function for suppressing the warning message. Additionally, the patch adds
> memset() to initialize a node struct into register_node(). Because the node
> struct is part of node_devices[] array and it cannot be freed by
> node_device_release(). So if system reuses the node struct, it has a garbage.
>

Nice catch on reuse of the statically allocated node_devices[] for node
hotplug.

> CC: David Rientjes <[email protected]>
> CC: Jiang Liu <[email protected]>
> Cc: Minchan Kim <[email protected]>
> CC: Andrew Morton <[email protected]>
> CC: KOSAKI Motohiro <[email protected]>
> Signed-off-by: Yasuaki Ishimatsu <[email protected]>
> Signed-off-by: Wen Congyang <[email protected]>

Can register_node() be made static in drivers/base/node.c and its
declaration removed from linux/node.h?

Acked-by: David Rientjes <[email protected]>

2012-10-11 22:31:15

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH 1/2]suppress "Device memoryX does not have a release() function" warning

On Thu, Oct 11, 2012 at 1:22 AM, Yasuaki Ishimatsu
<[email protected]> wrote:
> When calling remove_memory_block(), the function shows following message at
> device_release().
>
> "Device 'memory528' does not have a release() function, it is broken and must
> be fixed."
>
> The reason is memory_block's device struct does not have a release() function.
>
> So the patch registers memory_block_release() to the device's release() function
> for suppressing the warning message. Additionally, the patch moves kfree(mem)
> into the release function since the release function is prepared as a means
> to free a memory_block struct.
>
> CC: David Rientjes <[email protected]>
> CC: Jiang Liu <[email protected]>
> Cc: Minchan Kim <[email protected]>
> CC: Andrew Morton <[email protected]>
> CC: KOSAKI Motohiro <[email protected]>
> CC: Wen Congyang <[email protected]>
> Signed-off-by: Yasuaki Ishimatsu <[email protected]>

Acked-by: KOSAKI Motohiro <[email protected]>

2012-10-11 22:33:45

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

On Thu, Oct 11, 2012 at 1:26 AM, Yasuaki Ishimatsu
<[email protected]> wrote:
> When calling unregister_node(), the function shows following message at
> device_release().
>
> "Device 'node2' does not have a release() function, it is broken and must
> be fixed."
>
> The reason is node's device struct does not have a release() function.
>
> So the patch registers node_device_release() to the device's release()
> function for suppressing the warning message. Additionally, the patch adds
> memset() to initialize a node struct into register_node(). Because the node
> struct is part of node_devices[] array and it cannot be freed by
> node_device_release(). So if system reuses the node struct, it has a garbage.
>
> CC: David Rientjes <[email protected]>
> CC: Jiang Liu <[email protected]>
> Cc: Minchan Kim <[email protected]>
> CC: Andrew Morton <[email protected]>
> CC: KOSAKI Motohiro <[email protected]>
> Signed-off-by: Yasuaki Ishimatsu <[email protected]>
> Signed-off-by: Wen Congyang <[email protected]>
> ---
> drivers/base/node.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> Index: linux-3.6/drivers/base/node.c
> ===================================================================
> --- linux-3.6.orig/drivers/base/node.c 2012-10-11 10:04:02.149758748 +0900
> +++ linux-3.6/drivers/base/node.c 2012-10-11 10:20:34.111806931 +0900
> @@ -252,6 +252,14 @@ static inline void hugetlb_register_node
> static inline void hugetlb_unregister_node(struct node *node) {}
> #endif
>
> +static void node_device_release(struct device *dev)
> +{
> +#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
> + struct node *node_dev = to_node(dev);
> +
> + flush_work(&node_dev->node_work);
> +#endif
> +}

The patch description don't explain why this flush_work() is needed.


> /*
> * register_node - Setup a sysfs device for a node.
> @@ -263,8 +271,11 @@ int register_node(struct node *node, int
> {
> int error;
>
> + memset(node, 0, sizeof(*node));
> +

You should add a comment why we need initialize a node here. A lot
of developers don't have hotplug knowledge.

2012-10-12 00:14:35

by Yasuaki Ishimatsu

[permalink] [raw]
Subject: Re: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

2012/10/12 5:31, David Rientjes wrote:
> On Thu, 11 Oct 2012, Yasuaki Ishimatsu wrote:
>
>> When calling unregister_node(), the function shows following message at
>> device_release().
>>
>> "Device 'node2' does not have a release() function, it is broken and must
>> be fixed."
>>
>> The reason is node's device struct does not have a release() function.
>>
>> So the patch registers node_device_release() to the device's release()
>> function for suppressing the warning message. Additionally, the patch adds
>> memset() to initialize a node struct into register_node(). Because the node
>> struct is part of node_devices[] array and it cannot be freed by
>> node_device_release(). So if system reuses the node struct, it has a garbage.
>>
>
> Nice catch on reuse of the statically allocated node_devices[] for node
> hotplug.
>
>> CC: David Rientjes <[email protected]>
>> CC: Jiang Liu <[email protected]>
>> Cc: Minchan Kim <[email protected]>
>> CC: Andrew Morton <[email protected]>
>> CC: KOSAKI Motohiro <[email protected]>
>> Signed-off-by: Yasuaki Ishimatsu <[email protected]>
>> Signed-off-by: Wen Congyang <[email protected]>
>
> Can register_node() be made static in drivers/base/node.c and its
> declaration removed from linux/node.h?

Yah. I'll fix it.

Thanks,
Yasuaki Ishimatsu

>
> Acked-by: David Rientjes <[email protected]>
>

2012-10-17 06:18:34

by Wen Congyang

[permalink] [raw]
Subject: Re: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

At 10/12/2012 06:33 AM, KOSAKI Motohiro Wrote:
> On Thu, Oct 11, 2012 at 1:26 AM, Yasuaki Ishimatsu
> <[email protected]> wrote:
>> When calling unregister_node(), the function shows following message at
>> device_release().
>>
>> "Device 'node2' does not have a release() function, it is broken and must
>> be fixed."
>>
>> The reason is node's device struct does not have a release() function.
>>
>> So the patch registers node_device_release() to the device's release()
>> function for suppressing the warning message. Additionally, the patch adds
>> memset() to initialize a node struct into register_node(). Because the node
>> struct is part of node_devices[] array and it cannot be freed by
>> node_device_release(). So if system reuses the node struct, it has a garbage.
>>
>> CC: David Rientjes <[email protected]>
>> CC: Jiang Liu <[email protected]>
>> Cc: Minchan Kim <[email protected]>
>> CC: Andrew Morton <[email protected]>
>> CC: KOSAKI Motohiro <[email protected]>
>> Signed-off-by: Yasuaki Ishimatsu <[email protected]>
>> Signed-off-by: Wen Congyang <[email protected]>
>> ---
>> drivers/base/node.c | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>>
>> Index: linux-3.6/drivers/base/node.c
>> ===================================================================
>> --- linux-3.6.orig/drivers/base/node.c 2012-10-11 10:04:02.149758748 +0900
>> +++ linux-3.6/drivers/base/node.c 2012-10-11 10:20:34.111806931 +0900
>> @@ -252,6 +252,14 @@ static inline void hugetlb_register_node
>> static inline void hugetlb_unregister_node(struct node *node) {}
>> #endif
>>
>> +static void node_device_release(struct device *dev)
>> +{
>> +#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
>> + struct node *node_dev = to_node(dev);
>> +
>> + flush_work(&node_dev->node_work);
>> +#endif
>> +}
>
> The patch description don't explain why this flush_work() is needed.

If the node is onlined after it is offlined, we will clear the memory,
so we should flush_work() before node_dev is set to 0.

Thanks
Wen Congyang

>
>
>> /*
>> * register_node - Setup a sysfs device for a node.
>> @@ -263,8 +271,11 @@ int register_node(struct node *node, int
>> {
>> int error;
>>
>> + memset(node, 0, sizeof(*node));
>> +
>
> You should add a comment why we need initialize a node here. A lot
> of developers don't have hotplug knowledge.
>

2012-10-17 08:51:03

by KOSAKI Motohiro

[permalink] [raw]
Subject: Re: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

On Wed, Oct 17, 2012 at 2:24 AM, Wen Congyang <[email protected]> wrote:
> At 10/12/2012 06:33 AM, KOSAKI Motohiro Wrote:
>> On Thu, Oct 11, 2012 at 1:26 AM, Yasuaki Ishimatsu
>> <[email protected]> wrote:
>>> When calling unregister_node(), the function shows following message at
>>> device_release().
>>>
>>> "Device 'node2' does not have a release() function, it is broken and must
>>> be fixed."
>>>
>>> The reason is node's device struct does not have a release() function.
>>>
>>> So the patch registers node_device_release() to the device's release()
>>> function for suppressing the warning message. Additionally, the patch adds
>>> memset() to initialize a node struct into register_node(). Because the node
>>> struct is part of node_devices[] array and it cannot be freed by
>>> node_device_release(). So if system reuses the node struct, it has a garbage.
>>>
>>> CC: David Rientjes <[email protected]>
>>> CC: Jiang Liu <[email protected]>
>>> Cc: Minchan Kim <[email protected]>
>>> CC: Andrew Morton <[email protected]>
>>> CC: KOSAKI Motohiro <[email protected]>
>>> Signed-off-by: Yasuaki Ishimatsu <[email protected]>
>>> Signed-off-by: Wen Congyang <[email protected]>
>>> ---
>>> drivers/base/node.c | 11 +++++++++++
>>> 1 file changed, 11 insertions(+)
>>>
>>> Index: linux-3.6/drivers/base/node.c
>>> ===================================================================
>>> --- linux-3.6.orig/drivers/base/node.c 2012-10-11 10:04:02.149758748 +0900
>>> +++ linux-3.6/drivers/base/node.c 2012-10-11 10:20:34.111806931 +0900
>>> @@ -252,6 +252,14 @@ static inline void hugetlb_register_node
>>> static inline void hugetlb_unregister_node(struct node *node) {}
>>> #endif
>>>
>>> +static void node_device_release(struct device *dev)
>>> +{
>>> +#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
>>> + struct node *node_dev = to_node(dev);
>>> +
>>> + flush_work(&node_dev->node_work);
>>> +#endif
>>> +}
>>
>> The patch description don't explain why this flush_work() is needed.
>
> If the node is onlined after it is offlined, we will clear the memory,
> so we should flush_work() before node_dev is set to 0.

So then, it is irrelevant from warning supressness. You should make an
another patch.

2012-10-19 05:36:29

by Wen Congyang

[permalink] [raw]
Subject: Re: [PATCH 2/2]suppress "Device nodeX does not have a release() function" warning

At 10/17/2012 04:50 PM, KOSAKI Motohiro Wrote:
> On Wed, Oct 17, 2012 at 2:24 AM, Wen Congyang <[email protected]> wrote:
>> At 10/12/2012 06:33 AM, KOSAKI Motohiro Wrote:
>>> On Thu, Oct 11, 2012 at 1:26 AM, Yasuaki Ishimatsu
>>> <[email protected]> wrote:
>>>> When calling unregister_node(), the function shows following message at
>>>> device_release().
>>>>
>>>> "Device 'node2' does not have a release() function, it is broken and must
>>>> be fixed."
>>>>
>>>> The reason is node's device struct does not have a release() function.
>>>>
>>>> So the patch registers node_device_release() to the device's release()
>>>> function for suppressing the warning message. Additionally, the patch adds
>>>> memset() to initialize a node struct into register_node(). Because the node
>>>> struct is part of node_devices[] array and it cannot be freed by
>>>> node_device_release(). So if system reuses the node struct, it has a garbage.
>>>>
>>>> CC: David Rientjes <[email protected]>
>>>> CC: Jiang Liu <[email protected]>
>>>> Cc: Minchan Kim <[email protected]>
>>>> CC: Andrew Morton <[email protected]>
>>>> CC: KOSAKI Motohiro <[email protected]>
>>>> Signed-off-by: Yasuaki Ishimatsu <[email protected]>
>>>> Signed-off-by: Wen Congyang <[email protected]>
>>>> ---
>>>> drivers/base/node.c | 11 +++++++++++
>>>> 1 file changed, 11 insertions(+)
>>>>
>>>> Index: linux-3.6/drivers/base/node.c
>>>> ===================================================================
>>>> --- linux-3.6.orig/drivers/base/node.c 2012-10-11 10:04:02.149758748 +0900
>>>> +++ linux-3.6/drivers/base/node.c 2012-10-11 10:20:34.111806931 +0900
>>>> @@ -252,6 +252,14 @@ static inline void hugetlb_register_node
>>>> static inline void hugetlb_unregister_node(struct node *node) {}
>>>> #endif
>>>>
>>>> +static void node_device_release(struct device *dev)
>>>> +{
>>>> +#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
>>>> + struct node *node_dev = to_node(dev);
>>>> +
>>>> + flush_work(&node_dev->node_work);
>>>> +#endif
>>>> +}
>>>
>>> The patch description don't explain why this flush_work() is needed.
>>
>> If the node is onlined after it is offlined, we will clear the memory,
>> so we should flush_work() before node_dev is set to 0.
>
> So then, it is irrelevant from warning supressness. You should make an
> another patch.
>

OK, I will update it soon.

Thanks
Wen Congyang