Skip to contentSkip to conversation

4/7 replace uml_strdup by kstrdup

PATCH In review [email protected] 3 participants 5 messages Feb 1, 2005 – Feb 4, 2005 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 4/7 replace uml_strdup by kstrdup

This patch removes the strdup implementation in the UML architecture (uml_strdup), and updates it to use the kstrdup library function.

--
Paulo Marques - www.grupopie.com

All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke (1729 - 1797)

arch/um/drivers/cow_sys.h +0 -5
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/drivers/cow_sys.h linux-2.6.11-rc2-bk9/arch/um/drivers/cow_sys.h
@@ -18,11 +18,6 @@ static inline void cow_free(void *ptr)
 
 #define cow_printf printk
 
-static inline char *cow_strdup(char *str)
-{
-	return(uml_strdup(str));
-}
-
 static inline int cow_seek_file(int fd, unsigned long long offset)
 {
 	return(os_seek_file(fd, offset));
arch/um/drivers/cow_user.c +2 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/drivers/cow_user.c linux-2.6.11-rc2-bk9/arch/um/drivers/cow_user.c
@@ -7,6 +7,7 @@
 #include <sys/param.h>
 #include <sys/user.h>
 #include <netinet/in.h>
+#include <linux/string.h>
 
 #include "os.h"
 
@@ -313,7 +314,7 @@ int read_cow_header(int (*reader)(__u64,
 		goto out;
 	}
 	err = -ENOMEM;
-	*backing_file_out = cow_strdup(file);
+	*backing_file_out = kstrdup(file, GFP_KERNEL);
 	if(*backing_file_out == NULL){
 		cow_printf("read_cow_header - failed to allocate backing "
 			   "file\n");
arch/um/drivers/line.c +5 -4
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/drivers/line.c linux-2.6.11-rc2-bk9/arch/um/drivers/line.c
@@ -9,6 +9,7 @@
 #include "linux/kd.h"
 #include "linux/interrupt.h"
 #include "linux/devfs_fs_kernel.h"
+#include "linux/string.h"
 #include "asm/uaccess.h"
 #include "chan_kern.h"
 #include "irq_user.h"
@@ -445,10 +446,10 @@ int line_setup(struct line *lines, int n
 
 int line_config(struct line *lines, int num, char *str)
 {
-	char *new = uml_strdup(str);
+	char *new = kstrdup(str, GFP_KERNEL);
 
 	if(new == NULL){
-		printk("line_config - uml_strdup failed\n");
+		printk("line_config - kstrdup failed\n");
 		return(-ENOMEM);
 	}
 	return(!line_setup(lines, num, new, 0));
@@ -555,9 +556,9 @@ void lines_init(struct line *lines, int 
 		INIT_LIST_HEAD(&line->chan_list);
 		sema_init(&line->sem, 1);
 		if(line->init_str != NULL){
-			line->init_str = uml_strdup(line->init_str);
+			line->init_str = kstrdup(line->init_str, GFP_KERNEL);
 			if(line->init_str == NULL)
-				printk("lines_init - uml_strdup returned "
+				printk("lines_init - kstrdup returned "
 				       "NULL\n");
 		}
 	}
arch/um/drivers/mconsole_kern.c +2 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/drivers/mconsole_kern.c linux-2.6.11-rc2-bk9/arch/um/drivers/mconsole_kern.c
@@ -20,6 +20,7 @@
 #include "linux/namei.h"
 #include "linux/proc_fs.h"
 #include "linux/syscalls.h"
+#include "linux/string.h"
 #include "asm/irq.h"
 #include "asm/uaccess.h"
 #include "user_util.h"
@@ -483,7 +484,7 @@ int mconsole_init(void)
 	}
 
 	if(notify_socket != NULL){
-		notify_socket = uml_strdup(notify_socket);
+		notify_socket = kstrdup(notify_socket, GFP_KERNEL);
 		if(notify_socket != NULL)
 			mconsole_notify(notify_socket, MCONSOLE_SOCKET,
 					mconsole_socket_name, 
arch/um/drivers/net_kern.c +2 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/drivers/net_kern.c linux-2.6.11-rc2-bk9/arch/um/drivers/net_kern.c
@@ -20,6 +20,7 @@
 #include "linux/ctype.h"
 #include "linux/bootmem.h"
 #include "linux/ethtool.h"
+#include "linux/string.h"
 #include "asm/uaccess.h"
 #include "user_util.h"
 #include "kern_util.h"
@@ -602,7 +603,7 @@ static int net_config(char *str)
 	err = eth_parse(str, &n, &str);
 	if(err) return(err);
 
-	str = uml_strdup(str);
+	str = kstrdup(str, GFP_KERNEL);
 	if(str == NULL){
 		printk(KERN_ERR "net_config failed to strdup string\n");
 		return(-1);
arch/um/drivers/ubd_kern.c +2 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/drivers/ubd_kern.c linux-2.6.11-rc2-bk9/arch/um/drivers/ubd_kern.c
@@ -35,6 +35,7 @@
 #include "linux/blkpg.h"
 #include "linux/genhd.h"
 #include "linux/spinlock.h"
+#include "linux/string.h"
 #include "asm/segment.h"
 #include "asm/uaccess.h"
 #include "asm/irq.h"
@@ -722,7 +723,7 @@ static int ubd_config(char *str)
 {
 	int n, err;
 
-	str = uml_strdup(str);
+	str = kstrdup(str, GFP_KERNEL);
 	if(str == NULL){
 		printk(KERN_ERR "ubd_config failed to strdup string\n");
 		return(1);
arch/um/include/kern_util.h +0 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/include/kern_util.h linux-2.6.11-rc2-bk9/arch/um/include/kern_util.h
@@ -85,7 +85,6 @@ extern int attach_debugger(int idle_pid,
 extern void bad_segv(unsigned long address, unsigned long ip, int is_write);
 extern int config_gdb(char *str);
 extern int remove_gdb(void);
-extern char *uml_strdup(char *string);
 extern void unprotect_kernel_mem(void);
 extern void protect_kernel_mem(void);
 extern void uml_cleanup(void);
arch/um/kernel/ksyms.c +0 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/kernel/ksyms.c linux-2.6.11-rc2-bk9/arch/um/kernel/ksyms.c
@@ -61,7 +61,6 @@ EXPORT_SYMBOL(strncpy_from_user_skas);
 EXPORT_SYMBOL(copy_to_user_skas);
 EXPORT_SYMBOL(copy_from_user_skas);
 #endif
-EXPORT_SYMBOL(uml_strdup);
 
 EXPORT_SYMBOL(os_stat_fd);
 EXPORT_SYMBOL(os_stat_file);
arch/um/kernel/process_kern.c +0 -10
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/kernel/process_kern.c linux-2.6.11-rc2-bk9/arch/um/kernel/process_kern.c
@@ -353,16 +353,6 @@ void do_uml_exitcalls(void)
 		(*call)();
 }
 
-char *uml_strdup(char *string)
-{
-	char *new;
-
-	new = kmalloc(strlen(string) + 1, GFP_KERNEL);
-	if(new == NULL) return(NULL);
-	strcpy(new, string);
-	return(new);
-}
-
 void *get_init_task(void)
 {
 	return(&init_thread_union.thread_info.task);
arch/um/kernel/tempfile.c +1 -0
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/kernel/tempfile.c linux-2.6.11-rc2-bk9/arch/um/kernel/tempfile.c
@@ -9,6 +9,7 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/param.h>
+#include <linux/string.h>
 #include "init.h"
 
 /* Modified from create_mem_file and start_debugger */
arch/um/kernel/tt/gdb.c +2 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/kernel/tt/gdb.c linux-2.6.11-rc2-bk9/arch/um/kernel/tt/gdb.c
@@ -10,6 +10,7 @@
 #include <signal.h>
 #include <sys/ptrace.h>
 #include <sys/types.h>
+#include <linux/string.h>
 #include "uml-config.h"
 #include "kern_constants.h"
 #include "chan_user.h"
@@ -200,7 +201,7 @@ int attach_debugger(int idle_pid, int pi
 #ifdef notdef /* Put this back in when it does something useful */
 static int __init uml_gdb_init_setup(char *line, int *add)
 {
-	gdb_init = uml_strdup(line);
+	gdb_init = kstrdup(line, GFP_KERNEL);
 	return 0;
 }
 
arch/um/os-Linux/drivers/tuntap_user.c +2 -1
diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c linux-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c
@@ -15,6 +15,7 @@
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <linux/if_tun.h>
+#include <linux/string.h>
 #include "net_user.h"
 #include "tuntap.h"
 #include "kern_util.h"
@@ -175,7 +176,7 @@ static int tuntap_open(void *data)
 			return(err);
 		}
 
-		pri->dev_name = uml_strdup(buffer);
+		pri->dev_name = kstrdup(buffer);
 		output += IFNAMSIZ;
 		printk("%s", output);
 		free_output_buffer(buffer);
#1 lore raw
Quoted 3 lines · On Tue, 1 Feb 2005 03:28:31 +0000, [email protected]…

diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c linux-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c

arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000 renamed from arch/um/os-Linux/drivers/tuntap_user.c 2004-12-24 21:35:40.000000000 +0000 +0 -0

[snip]

arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000

Quoted 2 lines
arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000 renamed from arch/um/os-Linux/drivers/tuntap_user.c 2004-12-24 21:35:40.000000000 +0000 +1 -1
-               pri->dev_name = uml_strdup(buffer);
+               pri->dev_name = kstrdup(buffer);

Please compile-test before submitting.

Pekka

-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw
Quoted 11 lines · Pekka Enberg
Quoted 3 lines · On Tue, 1 Feb 2005 03:28:31 +0000, [email protected]…

diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c linux-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c

arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000 renamed from arch/um/os-Linux/drivers/tuntap_user.c 2004-12-24 21:35:40.000000000 +0000 +0 -0

[snip]

Quoted 5 lines

arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000

Quoted 2 lines
arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000 renamed from arch/um/os-Linux/drivers/tuntap_user.c 2004-12-24 21:35:40.000000000 +0000 +1 -1
-               pri->dev_name = uml_strdup(buffer);
+               pri->dev_name = kstrdup(buffer);

Please compile-test before submitting.

I'm really sorry about this...

I've compiled with an allyesconfig to validate the changes, but that doesn't build the UML parts :(

Anyway, thanks for pointing this out. I still haven't got feedback regarding the acceptance of these patches. If there is a chance they're accepted, maybe the best thing to do is to post the series again with this correction and the sound patch corrections.

Signature · 4 lines
Paulo Marques - www.grupopie.com

All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)
#3 lore raw
Quoted 17 lines · you
Quoted 16 lines · Pekka Enberg

On Tue, 1 Feb 2005 03:28:31 +0000, [email protected]

Quoted 7 lines · <[email protected]> wrote:

diff -buprN -X dontdiff vanilla-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c linux-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c --- vanilla-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c

2004-12-24 21:35:40.000000000 +0000 +++

linux-2.6.11-rc2-bk9/arch/um/os-Linux/drivers/tuntap_user.c 2005-01-31 20:39:08.591154025 +0000

[snip]

Quoted 2 lines
arch/um/os-Linux/drivers/tuntap_user.c +1 -1
-               pri->dev_name = uml_strdup(buffer);
+               pri->dev_name = kstrdup(buffer);
Quoted 6 lines
Quoted 1 line

Please compile-test before submitting.

I'm really sorry about this...

I've compiled with an allyesconfig to validate the changes, but that doesn't build the UML parts :(

Well, the answer is to do add a "ARCH=um" to the build commands... you could maybe use a "make defconfig ARCH=um" however because UML itself, sometimes, does not build with allyesconfig /allmodconfig...

However, that said, there are bigger problems for UML.

Since of its particular nature, it contains some code which is compiled against userspace headers. For instance cow_user.c (the list includes *_user.c and everything that is explicitly listed in USER_OBJS inside the Makefiles)

So, for cow_user.c, when you add <linux/string.h> to cow_user.c, you are actually making it include /usr/include/linux/string.h...

For UML, you should probably add the prototype to a good header inside arch/um/include (those headers are in the searchpath for every file under arch/um) - probably the one which declared uml_strdup. Yes, we have had to duplicate prototypes for many functions... for inlines, we've had to provide in many case a non-inline version.

Quoted 4 lines

Anyway, thanks for pointing this out. I still haven't got feedback regarding the acceptance of these patches. If there is a chance they're accepted, maybe the best thing to do is to post the series again with this correction and the sound patch corrections.

Signature · 16 lines
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
http://www.user-mode-linux.org/~blaisorblade




-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
#4 lore raw
Quoted 2 lines · Blaisorblade

[...]
For UML, you should probably add the prototype to a good header inside arch/um/include (those headers are in the searchpath for every file under arch/um) - probably the one which declared uml_strdup. Yes, we have had to duplicate prototypes for many functions... for inlines, we've had to provide in many case a non-inline version.

Thanks for the tip. I'll have to read the code more carefully to understand better where the userspace ends and the kernel begins, so that I don't do similar mistakes in the future.

I'll redo the patch and post it for review, probably during next week. I don't think there is much hurry, because, even if this gets accepted, it should go in only in 2.6.12-rc1-mm1 or something like that, so there is still time to review this more carefully.

Thanks for reviewing the patch,

Signature · 15 lines
Paulo Marques - www.grupopie.com

All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke (1729 - 1797)


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel