All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Driver Core patches for 2.6.9
Date: Tue, 19 Oct 2004 09:37:07 -0700	[thread overview]
Message-ID: <10982038272844@kroah.com> (raw)
In-Reply-To: <10982038243480@kroah.com>

ChangeSet 1.1993, 2004/09/29 17:24:36-07:00, roland@topspin.com

[PATCH] kobject: add add_hotplug_env_var()

Add a (non-inlined) add_hotplug_env_var() function to <linux/kobject.h>
and lib/kobject.c.  There's a lot of boilerplate code involved in
setting environment variables in a hotplug method, so we should have a
convenience function to consolidate it (and avoid subtle bugs).


Signed-off-by: Roland Dreier <roland@topspin.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 include/linux/kobject.h |   10 ++++++++-
 lib/kobject_uevent.c    |   52 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)


diff -Nru a/include/linux/kobject.h b/include/linux/kobject.h
--- a/include/linux/kobject.h	2004-10-19 09:20:35 -07:00
+++ b/include/linux/kobject.h	2004-10-19 09:20:35 -07:00
@@ -237,9 +237,17 @@
 extern void subsys_remove_file(struct subsystem * , struct subsys_attribute *);
 
 #ifdef CONFIG_HOTPLUG
-extern void kobject_hotplug(struct kobject *kobj, enum kobject_action action);
+void kobject_hotplug(struct kobject *kobj, enum kobject_action action);
+int add_hotplug_env_var(char **envp, int num_envp, int *cur_index,
+			char *buffer, int buffer_size, int *cur_len,
+			const char *format, ...)
+	__attribute__((format (printf, 7, 8)));
 #else
 static inline void kobject_hotplug(struct kobject *kobj, enum kobject_action action) { }
+static inline int add_hotplug_env_var(char **envp, int num_envp, int *cur_index, 
+				      char *buffer, int buffer_size, int *cur_len, 
+				      const char *format, ...)
+{ return 0; }
 #endif
 
 #endif /* __KERNEL__ */
diff -Nru a/lib/kobject_uevent.c b/lib/kobject_uevent.c
--- a/lib/kobject_uevent.c	2004-10-19 09:20:35 -07:00
+++ b/lib/kobject_uevent.c	2004-10-19 09:20:35 -07:00
@@ -290,6 +290,56 @@
 	return;
 }
 EXPORT_SYMBOL(kobject_hotplug);
-#endif /* CONFIG_HOTPLUG */
 
+/**
+ * add_hotplug_env_var - helper for creating hotplug environment variables
+ * @envp: Pointer to table of environment variables, as passed into
+ * hotplug() method.
+ * @num_envp: Number of environment variable slots available, as
+ * passed into hotplug() method.
+ * @cur_index: Pointer to current index into @envp.  It should be
+ * initialized to 0 before the first call to add_hotplug_env_var(),
+ * and will be incremented on success.
+ * @buffer: Pointer to buffer for environment variables, as passed
+ * into hotplug() method.
+ * @buffer_size: Length of @buffer, as passed into hotplug() method.
+ * @cur_len: Pointer to current length of space used in @buffer.
+ * Should be initialized to 0 before the first call to
+ * add_hotplug_env_var(), and will be incremented on success.
+ * @format: Format for creating environment variable (of the form
+ * "XXX=%x") for snprintf().
+ *
+ * Returns 0 if environment variable was added successfully or -ENOMEM
+ * if no space was available.
+ */
+int add_hotplug_env_var(char **envp, int num_envp, int *cur_index,
+			char *buffer, int buffer_size, int *cur_len,
+			const char *format, ...)
+{
+	va_list args;
+
+	/*
+	 * We check against num_envp - 1 to make sure there is at
+	 * least one slot left after we return, since the hotplug
+	 * method needs to set the last slot to NULL.
+	 */
+	if (*cur_index >= num_envp - 1)
+		return -ENOMEM;
+
+	envp[*cur_index] = buffer + *cur_len;
+
+	va_start(args, format);
+	*cur_len += vsnprintf(envp[*cur_index],
+			      max(buffer_size - *cur_len, 0),
+			      format, args) + 1;
+	va_end(args);
 
+	if (*cur_len > buffer_size)
+		return -ENOMEM;
+
+	(*cur_index)++;
+	return 0;
+}
+EXPORT_SYMBOL(add_hotplug_env_var);
+
+#endif /* CONFIG_HOTPLUG */


  reply	other threads:[~2004-10-19 17:00 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-19 16:34 [BK PATCH] Driver Core patches for 2.6.9 Greg KH
2004-10-19 16:35 ` [PATCH] " Greg KH
2004-10-19 16:35   ` Greg KH
2004-10-19 16:36     ` Greg KH
2004-10-19 16:36       ` Greg KH
2004-10-19 16:36         ` Greg KH
2004-10-19 16:36           ` Greg KH
2004-10-19 16:36             ` Greg KH
2004-10-19 16:36               ` Greg KH
2004-10-19 16:36                 ` Greg KH
2004-10-19 16:36                   ` Greg KH
2004-10-19 16:36                     ` Greg KH
2004-10-19 16:36                       ` Greg KH
2004-10-19 16:36                         ` Greg KH
2004-10-19 16:36                           ` Greg KH
2004-10-19 16:36                             ` Greg KH
2004-10-19 16:36                               ` Greg KH
2004-10-19 16:36                                 ` Greg KH
2004-10-19 16:36                                   ` Greg KH
2004-10-19 16:36                                     ` Greg KH
2004-10-19 16:36                                       ` Greg KH
2004-10-19 16:36                                         ` Greg KH
2004-10-19 16:36                                           ` Greg KH
2004-10-19 16:36                                             ` Greg KH
2004-10-19 16:36                                               ` Greg KH
2004-10-19 16:36                                                 ` Greg KH
2004-10-19 16:36                                                   ` Greg KH
2004-10-19 16:36                                                     ` Greg KH
2004-10-19 16:36                                                       ` Greg KH
2004-10-19 16:37                                                         ` Greg KH
2004-10-19 16:37                                                           ` Greg KH
2004-10-19 16:37                                                             ` Greg KH
2004-10-19 16:37                                                               ` Greg KH [this message]
2004-10-19 16:37                                                                 ` Greg KH
2004-10-19 16:37                                                                   ` Greg KH
2004-10-23 20:20                     ` Kronos
2004-10-23 20:34                       ` Greg KH
2004-10-23 21:46                         ` Kronos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10982038272844@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.