提交 542cfce6 编写于 作者: A Aneesh Kumar K.V 提交者: Greg Kroah-Hartman

kobject: kobject_uevent() returns manageable value

Since kobject_uevent() function does not return an integer value to
indicate if its operation was completed with success or not, it is worth
changing it in order to report a proper status (success or error) instead
of returning void.

[randy.dunlap@oracle.com: Fix inline kobject functions]
Cc: Mauricio Lin <mauriciolin@gmail.com>
Signed-off-by: NAneesh Kumar K.V <aneesh.kumar@gmail.com>
Signed-off-by: NRandy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 f334b60b
...@@ -265,8 +265,8 @@ extern int __must_check subsys_create_file(struct subsystem * , ...@@ -265,8 +265,8 @@ extern int __must_check subsys_create_file(struct subsystem * ,
struct subsys_attribute *); struct subsys_attribute *);
#if defined(CONFIG_HOTPLUG) #if defined(CONFIG_HOTPLUG)
void kobject_uevent(struct kobject *kobj, enum kobject_action action); int kobject_uevent(struct kobject *kobj, enum kobject_action action);
void kobject_uevent_env(struct kobject *kobj, enum kobject_action action, int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
char *envp[]); char *envp[]);
int add_uevent_var(char **envp, int num_envp, int *cur_index, int add_uevent_var(char **envp, int num_envp, int *cur_index,
...@@ -274,11 +274,12 @@ int add_uevent_var(char **envp, int num_envp, int *cur_index, ...@@ -274,11 +274,12 @@ int add_uevent_var(char **envp, int num_envp, int *cur_index,
const char *format, ...) const char *format, ...)
__attribute__((format (printf, 7, 8))); __attribute__((format (printf, 7, 8)));
#else #else
static inline void kobject_uevent(struct kobject *kobj, enum kobject_action action) { } static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action)
static inline void kobject_uevent_env(struct kobject *kobj, { return 0; }
static inline int kobject_uevent_env(struct kobject *kobj,
enum kobject_action action, enum kobject_action action,
char *envp[]) char *envp[])
{ } { return 0; }
static inline int add_uevent_var(char **envp, int num_envp, int *cur_index, static inline int add_uevent_var(char **envp, int num_envp, int *cur_index,
char *buffer, int buffer_size, int *cur_len, char *buffer, int buffer_size, int *cur_len,
......
...@@ -63,8 +63,11 @@ static char *action_to_string(enum kobject_action action) ...@@ -63,8 +63,11 @@ static char *action_to_string(enum kobject_action action)
* @action: action that is happening (usually KOBJ_MOVE) * @action: action that is happening (usually KOBJ_MOVE)
* @kobj: struct kobject that the action is happening to * @kobj: struct kobject that the action is happening to
* @envp_ext: pointer to environmental data * @envp_ext: pointer to environmental data
*
* Returns 0 if kobject_uevent() is completed with success or the
* corresponding error when it fails.
*/ */
void kobject_uevent_env(struct kobject *kobj, enum kobject_action action, int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
char *envp_ext[]) char *envp_ext[])
{ {
char **envp; char **envp;
...@@ -79,14 +82,16 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action, ...@@ -79,14 +82,16 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
u64 seq; u64 seq;
char *seq_buff; char *seq_buff;
int i = 0; int i = 0;
int retval; int retval = 0;
int j; int j;
pr_debug("%s\n", __FUNCTION__); pr_debug("%s\n", __FUNCTION__);
action_string = action_to_string(action); action_string = action_to_string(action);
if (!action_string) if (!action_string) {
return; pr_debug("kobject attempted to send uevent without action_string!\n");
return -EINVAL;
}
/* search the kset we belong to */ /* search the kset we belong to */
top_kobj = kobj; top_kobj = kobj;
...@@ -95,31 +100,39 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action, ...@@ -95,31 +100,39 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
top_kobj = top_kobj->parent; top_kobj = top_kobj->parent;
} while (!top_kobj->kset && top_kobj->parent); } while (!top_kobj->kset && top_kobj->parent);
} }
if (!top_kobj->kset) if (!top_kobj->kset) {
return; pr_debug("kobject attempted to send uevent without kset!\n");
return -EINVAL;
}
kset = top_kobj->kset; kset = top_kobj->kset;
uevent_ops = kset->uevent_ops; uevent_ops = kset->uevent_ops;
/* skip the event, if the filter returns zero. */ /* skip the event, if the filter returns zero. */
if (uevent_ops && uevent_ops->filter) if (uevent_ops && uevent_ops->filter)
if (!uevent_ops->filter(kset, kobj)) if (!uevent_ops->filter(kset, kobj)) {
return; pr_debug("kobject filter function caused the event to drop!\n");
return 0;
}
/* environment index */ /* environment index */
envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL); envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL);
if (!envp) if (!envp)
return; return -ENOMEM;
/* environment values */ /* environment values */
buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL); buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
if (!buffer) if (!buffer) {
retval = -ENOMEM;
goto exit; goto exit;
}
/* complete object path */ /* complete object path */
devpath = kobject_get_path(kobj, GFP_KERNEL); devpath = kobject_get_path(kobj, GFP_KERNEL);
if (!devpath) if (!devpath) {
retval = -ENOENT;
goto exit; goto exit;
}
/* originating subsystem */ /* originating subsystem */
if (uevent_ops && uevent_ops->name) if (uevent_ops && uevent_ops->name)
...@@ -204,7 +217,7 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action, ...@@ -204,7 +217,7 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
kfree(devpath); kfree(devpath);
kfree(buffer); kfree(buffer);
kfree(envp); kfree(envp);
return; return retval;
} }
EXPORT_SYMBOL_GPL(kobject_uevent_env); EXPORT_SYMBOL_GPL(kobject_uevent_env);
...@@ -214,10 +227,13 @@ EXPORT_SYMBOL_GPL(kobject_uevent_env); ...@@ -214,10 +227,13 @@ EXPORT_SYMBOL_GPL(kobject_uevent_env);
* *
* @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE) * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE)
* @kobj: struct kobject that the action is happening to * @kobj: struct kobject that the action is happening to
*
* Returns 0 if kobject_uevent() is completed with success or the
* corresponding error when it fails.
*/ */
void kobject_uevent(struct kobject *kobj, enum kobject_action action) int kobject_uevent(struct kobject *kobj, enum kobject_action action)
{ {
kobject_uevent_env(kobj, action, NULL); return kobject_uevent_env(kobj, action, NULL);
} }
EXPORT_SYMBOL_GPL(kobject_uevent); EXPORT_SYMBOL_GPL(kobject_uevent);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册