Skip to contentSkip to conversation

net: netdev_kobject_init: annotate with __init

PATCH Applied Daniel Borkmann 3 participants 5 messages Jan 6, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: netdev_kobject_init: annotate with __init

netdev_kobject_init() is only being called from __init context, that is, net_dev_init(), so annotate it with __init as well, thus the kernel can take this as a hint that the function is used only during the initialization phase and free up used memory resources after its invocation.

---
 net/core/net-sysfs.c | 2 +-
 net/core/net-sysfs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/core/net-sysfs.c +1 -1
index 1a7b7b1..49843bf 100644
@@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
 }
 EXPORT_SYMBOL(netdev_class_remove_file_ns);
 
-int netdev_kobject_init(void)
+int __init netdev_kobject_init(void)
 {
 	kobj_ns_type_register(&net_ns_type_operations);
 	return class_register(&net_class);
net/core/net-sysfs.h +1 -1
index bd7751e..2745a1b 100644
@@ -1,7 +1,7 @@
 #ifndef __NET_SYSFS_H__
 #define __NET_SYSFS_H__
 
-int netdev_kobject_init(void);
+int __init netdev_kobject_init(void);
 int netdev_register_kobject(struct net_device *);
 void netdev_unregister_kobject(struct net_device *);
 int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num);
Signature · 1 line
1.7.11.7
maintainer Applied
#1 lore raw

From: Daniel Borkmann <[email protected]>
Date: Mon, 6 Jan 2014 01:20:11 +0100

Quoted 7 lines

netdev_kobject_init() is only being called from __init context, that is, net_dev_init(), so annotate it with __init as well, thus the kernel can take this as a hint that the function is used only during the initialization phase and free up used memory resources after its invocation.

Applied.

#2 lore raw
In reply to Daniel Borkmann

Hello.

Quoted 7 lines · Daniel Borkmann

netdev_kobject_init() is only being called from __init context, that is, net_dev_init(), so annotate it with __init as well, thus the kernel can take this as a hint that the function is used only during the initialization phase and free up used memory resources after its invocation.

[...]

net/core/net-sysfs.h line 4

Quoted 10 lines
net/core/net-sysfs.h +1 -1
index bd7751e..2745a1b 100644
@@ -1,7 +1,7 @@
  #ifndef __NET_SYSFS_H__
  #define __NET_SYSFS_H__
 
-int netdev_kobject_init(void);
+int __init netdev_kobject_init(void);

There's no need to also annotate function prototype.

WBR, Sergei

#3 lore raw
Quoted 21 lines · Sergei Shtylyov

Hello.

Quoted 7 lines · Daniel Borkmann

netdev_kobject_init() is only being called from __init context, that is, net_dev_init(), so annotate it with __init as well, thus the kernel can take this as a hint that the function is used only during the initialization phase and free up used memory resources after its invocation.

[...]

Quoted 8 lines
net/core/net-sysfs.h +0 -0
index bd7751e..2745a1b 100644
@@ -1,7 +1,7 @@
  #ifndef __NET_SYSFS_H__
  #define __NET_SYSFS_H__
 
Quoted 4 lines

net/core/net-sysfs.h line 4

Quoted 2 lines
net/core/net-sysfs.h +1 -1
-int netdev_kobject_init(void);
+int __init netdev_kobject_init(void);

There's no need to also annotate function prototype.

Hm, is that general convention? Having this in a header file annotated (even if not strictly necessary) would probably better prevent from possible misuse resp. section mismatches if people forget to look into the actual c file where the function is being defined.

Quoted 2 lines

WBR, Sergei

#4 lore raw
Quoted 17 lines · Daniel Borkmann
Quoted 17 lines
Quoted 7 lines

netdev_kobject_init() is only being called from __init context, that is, net_dev_init(), so annotate it with __init as well, thus the kernel can take this as a hint that the function is used only during the initialization phase and free up used memory resources after its invocation.

[...]

Quoted 8 lines
net/core/net-sysfs.h +0 -0
index bd7751e..2745a1b 100644
@@ -1,7 +1,7 @@
  #ifndef __NET_SYSFS_H__
  #define __NET_SYSFS_H__
 
Quoted 6 lines
Quoted 4 lines

net/core/net-sysfs.h line 4

Quoted 2 lines
net/core/net-sysfs.h +1 -1
-int netdev_kobject_init(void);
+int __init netdev_kobject_init(void);

There's no need to also annotate function prototype.

Hm, is that general convention?

More or less, though I've seen some prototypes annotated.

Quoted 5 lines

Having this in a header file
annotated (even if not strictly necessary) would probably better prevent from possible misuse resp. section mismatches if people forget to look into the actual c file where the function is being defined.

Dunno about vi users, I'm using Alt-. in EMACS when I want to find a
function, and it gets me right to the definition, not the prototype.

Quoted 1 line
Quoted 1 line

WBR, Sergei

PS: The patch was merged already, so my comment seems to have been posted too late anyway.

WBR, Sergei