public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: kobject_uevent() question
       [not found]   ` <20061128195532.GA13705@kroah.com>
@ 2006-12-10 17:04     ` Aneesh Kumar K.V
  2006-12-11 14:53       ` Mauricio Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Aneesh Kumar K.V @ 2006-12-10 17:04 UTC (permalink / raw)
  To: Greg KH, linux-kernel; +Cc: kernelnewbies

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

Greg KH wrote:
> On Tue, Nov 28, 2006 at 07:38:01PM +0000, Mauricio Lin wrote:
>> Hi Greg,
>>
>> It is working now. The failure was in the kobject_uevent() function. As
>> the kset of my kobject was not set properly, the kobject_uevent()
>> function just returned void.
>>
>> I wonder why the kobjec_uevent() does not return an integer to indicate
>> if the operation was completed with success or not.
> 
> Feel free to send patches fixing this issue :)
> 
> thanks,
> 
> 

Something like this ?

-aneesh

[-- Attachment #2: kobject_uevent.diff --]
[-- Type: text/x-patch, Size: 3970 bytes --]

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index d1c8d28..fc93c53 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -265,8 +265,8 @@ extern int __must_check subsys_create_file(struct subsystem * ,
 					struct subsys_attribute *);
 
 #if defined(CONFIG_HOTPLUG)
-void kobject_uevent(struct kobject *kobj, enum kobject_action action);
-void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
+int kobject_uevent(struct kobject *kobj, enum kobject_action action);
+int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 			char *envp[]);
 
 int add_uevent_var(char **envp, int num_envp, int *cur_index,
@@ -274,8 +274,8 @@ int add_uevent_var(char **envp, int num_envp, int *cur_index,
 			const char *format, ...)
 	__attribute__((format (printf, 7, 8)));
 #else
-static inline void kobject_uevent(struct kobject *kobj, enum kobject_action action) { }
-static inline void kobject_uevent_env(struct kobject *kobj,
+static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action) { }
+static inline int kobject_uevent_env(struct kobject *kobj,
 				      enum kobject_action action,
 				      char *envp[])
 { }
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index a192276..7eaf6f6 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -64,7 +64,7 @@ static char *action_to_string(enum kobject_action action)
  * @kobj: struct kobject that the action is happening to
  * @envp_ext: pointer to environmental data
  */
-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;
@@ -79,14 +79,16 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 	u64 seq;
 	char *seq_buff;
 	int i = 0;
-	int retval;
+	int retval = 0;
 	int j;
 
 	pr_debug("%s\n", __FUNCTION__);
 
 	action_string = action_to_string(action);
-	if (!action_string)
-		return;
+	if (!action_string) {
+		pr_debug("kobject attempted to send uevent without action_string!\n");
+		return -EINVAL;
+	}
 
 	/* search the kset we belong to */
 	top_kobj = kobj;
@@ -95,31 +97,39 @@ void kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 			top_kobj = top_kobj->parent;
 		} while (!top_kobj->kset && top_kobj->parent);
 	}
-	if (!top_kobj->kset)
-		return;
+	if (!top_kobj->kset) {
+		pr_debug("kobject attempted to send uevent without kset!\n");
+		return -EINVAL;
+	}
 
 	kset = top_kobj->kset;
 	uevent_ops = kset->uevent_ops;
 
 	/*  skip the event, if the filter returns zero. */
 	if (uevent_ops && uevent_ops->filter)
-		if (!uevent_ops->filter(kset, kobj))
-			return;
+		if (!uevent_ops->filter(kset, kobj)) {
+			pr_debug("kobject filter function caused the event to drop!\n");
+			return 0;
+		}
 
 	/* environment index */
 	envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL);
 	if (!envp)
-		return;
+		return -ENOMEM;
 
 	/* environment values */
 	buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
-	if (!buffer)
+	if (!buffer) {
+		retval = -ENOMEM;
 		goto exit;
+	}
 
 	/* complete object path */
 	devpath = kobject_get_path(kobj, GFP_KERNEL);
-	if (!devpath)
+	if (!devpath) {
+		retval = -ENOENT;
 		goto exit;
+	}
 
 	/* originating subsystem */
 	if (uevent_ops && uevent_ops->name)
@@ -204,7 +214,7 @@ exit:
 	kfree(devpath);
 	kfree(buffer);
 	kfree(envp);
-	return;
+	return retval;
 }
 
 EXPORT_SYMBOL_GPL(kobject_uevent_env);
@@ -215,9 +225,9 @@ EXPORT_SYMBOL_GPL(kobject_uevent_env);
  * @action: action that is happening (usually KOBJ_ADD and KOBJ_REMOVE)
  * @kobj: struct kobject that the action is happening to
  */
-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);

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

* Re: kobject_uevent() question
  2006-12-10 17:04     ` kobject_uevent() question Aneesh Kumar K.V
@ 2006-12-11 14:53       ` Mauricio Lin
  2006-12-11 16:31         ` Aneesh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Mauricio Lin @ 2006-12-11 14:53 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: Greg KH, linux-kernel, kernelnewbies

Hi Aneesh,

I have posted a patch for that as well. You can check it at
http://lkml.org/lkml/2006/11/30/315.

BR,

Mauricio Lin.

On 12/10/06, Aneesh Kumar K.V <aneesh.kumar@gmail.com> wrote:
> Greg KH wrote:
> > On Tue, Nov 28, 2006 at 07:38:01PM +0000, Mauricio Lin wrote:
> >> Hi Greg,
> >>
> >> It is working now. The failure was in the kobject_uevent() function. As
> >> the kset of my kobject was not set properly, the kobject_uevent()
> >> function just returned void.
> >>
> >> I wonder why the kobjec_uevent() does not return an integer to indicate
> >> if the operation was completed with success or not.
> >
> > Feel free to send patches fixing this issue :)
> >
> > thanks,
> >
> >
>
> Something like this ?
>
> -aneesh
>
>
>

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

* Re: kobject_uevent() question
  2006-12-11 14:53       ` Mauricio Lin
@ 2006-12-11 16:31         ` Aneesh Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Aneesh Kumar @ 2006-12-11 16:31 UTC (permalink / raw)
  To: Mauricio Lin; +Cc: Greg KH, linux-kernel, kernelnewbies

On 12/11/06, Mauricio Lin <mauriciolin@gmail.com> wrote:
> Hi Aneesh,
>
> I have posted a patch for that as well. You can check it at
> http://lkml.org/lkml/2006/11/30/315.
>


Changes i posted was with respect to a latest kernel and also had some
more failure case properly returning error. So i picked my diff added
the commit message and function documentation from your diff. I have
posted a new diff with sign-off. Let me know what you think.

-aneesh

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

end of thread, other threads:[~2006-12-11 16:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20061128161218.43358.qmail@web51813.mail.yahoo.com>
     [not found] ` <90539.55300.qm@web51815.mail.yahoo.com>
     [not found]   ` <20061128195532.GA13705@kroah.com>
2006-12-10 17:04     ` kobject_uevent() question Aneesh Kumar K.V
2006-12-11 14:53       ` Mauricio Lin
2006-12-11 16:31         ` Aneesh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox