init cleanups
v4 cover init cleanups
Hello,
This patchset tries to cleanup init/initramfs code especially for syscall invocation which produces many warnings from sparse because of address space change. This can be done by wrapping each syscall invocation and doing such conversions in it using kernel_sys_call() macro suggested by Arnd Bergmann.
This patchset depends on my previous patch "init: mark __user address space on string literals" [1] now contained in -mm tree. Actually now it can be replaced by these patches. Andrew, I can respin this if you want to remove my previous one in -mm tree.
Any comments would be welcomed.
Thanks.
[1] http://lkml.org/lkml/2010/8/18/157
---
* changes from v3:
make inverse christmas tree of headers :-)
macro name prefix is changed to 'kernel_sys_'
update some comments
* changes from v2:
use kern_sys_call() macro only on functions have pointer argument config option to use low-level VFS code removed
apply to all init/*.c not only initramfs code
* changes from v1:
introduce kern_sys_* wrappers instead of adding __force markups config option to use low-level VFS code added
Namhyung Kim (2):
init: add sys-wrapper.h
init: use kern_sys_* wrappers instead of syscall
init/do_mounts.c | 29 +++--- init/do_mounts_initrd.c | 48 ++++++----- init/do_mounts_md.c | 29 +++--- init/do_mounts_rd.c | 39 +++++---- init/initramfs.c | 64 +++++++------- init/main.c | 12 ++- init/noinitramfs.c | 12 ++- init/sys-wrapper.h | 216 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 338 insertions(+), 111 deletions(-) create mode 100644 init/sys-wrapper.h
--
1.7.2.2
PATCH v4 1/2 init: add sys-wrapper.h
sys-wrapper.h contains wrapper functions for various syscalls used in init code. This wrappers handle proper address space conversion so that it can remove a lot of warnings from sparse.
--- init/sys-wrapper.h | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 216 insertions(+), 0 deletions(-) create mode 100644 init/sys-wrapper.h
init/sys-wrapper.h new file +216 -0
@@ -0,0 +1,216 @@ +/* +* wrappers for various syscalls for use in the init code +* +* Copyright (C) 2010 Namhyung Kim <[email protected]> +* +* This file is released under the GPLv2. +*/ + +#include <linux/syscalls.h> +#include <linux/uaccess.h> +#include <linux/dirent.h> +#include <linux/types.h> +#include <linux/fs.h> + + +#define kernel_sys_call (call, ...) \ +({ \ + long result; \ + mm_segment_t old_fs = get_fs(); \ + set_fs(KERNEL_DS); \ + result = call(__VA_ARGS__); \ + set_fs(old_fs); \ + result; \ +}) + +static inline int kernel_sys_mount (char *dev_name,char *dir_name,char *type, +unsigned long flags,void *data) +{ +return kernel_sys_call (sys_mount, + (char __user __force *) dev_name, + (char __user __force *) dir_name, + (char __user __force *) type, + flags, + (void __user __force *) data); +} + +static inline int kernel_sys_umount (char *name,int flags) +{ +return kernel_sys_call (sys_umount, + (char __user __force *) name, flags); +} + +static inline int kernel_sys_chroot (const char *pathname) +{ +return kernel_sys_call (sys_chroot, + (const char __user __force *) pathname); +} + +static inline int kernel_sys_link (const char *oldname,const char *newname) +{ +return kernel_sys_call (sys_link, + (const char __user __force *) oldname, + (const char __user __force *) newname); +} + +static inline int kernel_sys_unlink (const char *pathname) +{ +return kernel_sys_call (sys_unlink, + (const char __user __force *) pathname); +} + +static inline int kernel_sys_newlstat (const char *filename, +struct stat *statbuf) +{ +return kernel_sys_call (sys_newlstat, + (const char __user __force *) filename, + (struct stat __user __force *) statbuf); +} + +static inline int kernel_sys_mkdir (const char *pathname,int mode) +{ +return kernel_sys_call (sys_mkdir, + (const char __user __force *) pathname, mode); +} + +static inline int kernel_sys_rmdir (const char *pathname) +{ +return kernel_sys_call (sys_rmdir, + (const char __user __force *) pathname); +} + +static inline int kernel_sys_chdir (const char *pathname) +{ +return kernel_sys_call (sys_chdir, + (const char __user __force *) pathname); +} + +static inline int kernel_sys_mknod (const char *filename, +int mode,unsigned dev) +{ +return kernel_sys_call (sys_mknod, + (const char __user __force *) filename, + mode, dev); +} + +static inline int kernel_sys_chown (const char *filename, +uid_t user,gid_t group) +{ +return kernel_sys_call (sys_chown, + (const char __user __force *) filename, + user, group); +} + +static inline int kernel_sys_chmod (const char *filename,mode_t mode) +{ +return kernel_sys_call (sys_chmod, + (const char __user __force *) filename, mode); +} + +static inline int kernel_sys_open (const char *filename,int flags,int mode) +{ +return kernel_sys_call (sys_open, + (const char __user __force *) filename, + flags, mode); +} + +static inline int kernel_sys_fchown (unsigned int fd,uid_t user,gid_t group) +{ +return sys_fchown (fd, user, group); +} + +static inline int kernel_sys_fchmod (unsigned int fd,mode_t mode) +{ +return sys_fchmod (fd, mode); +} + +static inline int kernel_sys_fchdir (unsigned int fd) +{ +return sys_fchdir (fd); +} + +static inline int kernel_sys_ftruncate (unsigned int fd,unsigned long length) +{ +return sys_ftruncate (fd, length); +} + +static inline int kernel_sys_read (unsigned int fd,char *buf,size_t count) +{ +return kernel_sys_call (sys_read, + fd, (char __user __force *) buf, count); +} + +static inline int kernel_sys_write (unsigned int fd,const char *buf, +size_t count) +{ +return kernel_sys_call (sys_write, + fd, (const char __user __force *) buf, count); +} + +static inline int kernel_sys_lseek (unsigned int fd,off_t offset, +unsigned int origin) +{ +return sys_lseek (fd, offset, origin); +} + +static inline int kernel_sys_ioctl (unsigned int fd,unsigned int cmd, +unsigned long arg) +{ +return sys_ioctl (fd, cmd, arg); +} + +static inline int kernel_sys_dup (unsigned int fd) +{ +return sys_dup (fd); +} + +static inline int kernel_sys_close (unsigned int fd) +{ +return sys_close (fd); +} + +static inline int kernel_sys_symlink (const char *oldname,const char *newname) +{ +return kernel_sys_call (sys_symlink, + (const char __user __force *) oldname, + (const char __user __force *) newname); +} + +static inline int kernel_sys_lchown (const char *filename,uid_t user, +gid_t group) +{ +return kernel_sys_call (sys_lchown, + (const char __user __force *) filename, + user, group); +} + +static inline int kernel_sys_getdents64 (unsigned int fd, +struct linux_dirent64 *dirent, +unsigned int count) +{ +return kernel_sys_call (sys_getdents64, + fd, + (struct linux_dirent64 __user __force *) dirent, + count); +} + +static inline int kernel_sys_access (const char *filename,int mode) +{ +return kernel_sys_call (sys_access, + (const char __user __force *) filename, mode); +} + +static inline int kernel_sys_setsid (void ) +{ +return sys_setsid (); +} + +static inline int kernel_sys_wait4 (pid_t upid,int *stat_addr,int options, +struct rusage *ru) +{ +return kernel_sys_call (sys_wait4, + upid, + (int __user __force *) stat_addr, + options, + (struct rusage __user __force *) ru); +}
Signature · 1 line
1.7.2.2
Re: [PATCH v4 1/2] init: add sys-wrapper.h
Quoted 3 lines · On Wed, 1 Sep 2010 00:30:18 +0900 Namhyung Kim <[email protected]> wrote:
sys-wrapper.hcontains wrapper functions for various syscalls used in init code. This wrappers handle proper address space conversion so that it can remove a lot of warnings from sparse.
This all looks pretty neat.
init/sys-wrapper.h line 24
Quoted 9 lines
init/sys-wrapper.h new file +9
-0+#define kernel_sys_call (call, ...) \ +({ \ + long result; \ + mm_segment_t old_fs = get_fs(); \ + set_fs(KERNEL_DS); \ + result = call(__VA_ARGS__); \ + set_fs(old_fs); \ + result; \ +})
I was worried that some syscalls don't need the set_fs(), and that this would add overhead. But I see that the patch addresses that.
Review
Quoted 2 lines
(quoted diff) +1
-1- int err = sys_mount(name, "/root", fs, flags, data); + int err = kernel_sys_mount(name, "/root", fs, flags, data);
It would be good if we could arrange for _all_ kernel syscalls to use the wrappers. ie: cause a direct call to sys_mount() to not compile?
I don't know how practical that would be.
Re: [PATCH v4 1/2] init: add sys-wrapper.h
Quoted 7 lines · Andrew Morton
Review
Quoted 2 lines
(quoted diff) +1
-1- int err = sys_mount(name, "/root", fs, flags, data); + int err = kernel_sys_mount(name, "/root", fs, flags, data);It would be good if we could arrange for all kernel syscalls to use the wrappers. ie: cause a direct call to
sys_mount()to not compile?I don't know how practical that would be.
One common reason to call a sys_* function is to implement another system call, e.g. sys_socketcall calling sys_socket or compat_sys_timer_create calling sys_timer_create.
I think in those cases we don't really want to go through another wrapper.
Arnd
Re: [PATCH v4 1/2] init: add sys-wrapper.h
Quoted 7 lines · On Sat, 18 Sep 2010 11:27:46 +0200 Arnd Bergmann <[email protected]> wrote:
Quoted 6 lines · Andrew Morton
Review
Quoted 2 lines
(quoted diff) +1
-1- int err = sys_mount(name, "/root", fs, flags, data); + int err = kernel_sys_mount(name, "/root", fs, flags, data);It would be good if we could arrange for all kernel syscalls to use the wrappers. ie: cause a direct call to
sys_mount()to not compile?
Quoted 8 lines
Quoted 1 line
I don't know how practical that would be.
One common reason to call a sys_* function is to implement another system call, e.g.
sys_socketcallcallingsys_socketorcompat_sys_timer_createcallingsys_timer_create.I think in those cases we don't really want to go through another wrapper.
The overhead is zero in the case of sys_socket() and somewhat non-zero in the case of sys_timer_create(). I can't immediately see a convenient way of reducing "somewhat" to zero.
PATCH v4 2/2 init: use kern_sys_* wrappers instead of syscall
In reply to Namhyung Kimreplace direct syscall invocations to its wrapper functions defined in init/sys-wrapper.h. This can remove following sparse warnings:
init/main.c:896:23: warning: cast adds address space to expression (<asn:1>)
...
init/do_mounts.c:220:29: warning: incorrect type in argument 1 (different address spaces)
init/do_mounts.c:220:29: expected char [noderef] <asn:1>*dev_name
init/do_mounts.c:220:29: got char *name
...
--- init/do_mounts.c | 29 +++++++++++---------- init/do_mounts_initrd.c | 48 ++++++++++++++++++----------------- init/do_mounts_md.c | 29 +++++++++++---------- init/do_mounts_rd.c | 39 ++++++++++++++-------------- init/initramfs.c | 64 ++++++++++++++++++++++++---------------------- init/main.c | 12 +++++--- init/noinitramfs.c | 12 +++++--- 7 files changed, 122 insertions(+), 111 deletions(-)
init/do_mounts.c +15 -14
@@ -21,6 +21,7 @@#include <linux/nfs_fs_sb.h> #include <linux/nfs_mount.h> +#include "sys-wrapper.h" #include "do_mounts.h" int __initdata rd_doload;/* 1 = load RAM disk, 0 = don't load */
@@ -217,11 +218,11 @@ static void __init get_fs_names(char *page)static int __init do_mount_root (char *name,char *fs,int flags,void *data) { -int err =sys_mount (name,"/root" , fs, flags, data); +int err =kernel_sys_mount (name,"/root" , fs, flags, data);if (err)return err; -sys_chdir ((const char __user __force *)"/root" ); +kernel_sys_chdir ("/root" );ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev; printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n", current->fs->pwd.mnt->mnt_sb->s_type->name,
@@ -287,7 +288,7 @@ retry: out:putname (fs_names); } - +#ifdef CONFIG_ROOT_NFS static int __init mount_nfs_root (void ) {
@@ -312,21 +313,21 @@ void __init change_floppy(char *fmt, ...)va_start (args, fmt);vsprintf (buf, fmt, args);va_end (args); - fd =sys_open ("/dev/root" ,O_RDWR |O_NDELAY ,0 ); + fd =kernel_sys_open ("/dev/root" ,O_RDWR |O_NDELAY ,0 );if (fd >=0 ) { -sys_ioctl (fd,FDEJECT ,0 ); -sys_close (fd); +kernel_sys_ioctl (fd,FDEJECT ,0 ); +kernel_sys_close (fd); }printk (KERN_NOTICE "VFS: Insert %s and press ENTER\n" , buf); - fd =sys_open ("/dev/console" ,O_RDWR ,0 ); + fd =kernel_sys_open ("/dev/console" ,O_RDWR ,0 );if (fd >=0 ) { -sys_ioctl (fd,TCGETS , (long )&termios); +kernel_sys_ioctl (fd,TCGETS , (long )&termios); termios.c_lflag &= ~ICANON ; -sys_ioctl (fd,TCSETSF , (long )&termios); -sys_read (fd, &c,1 ); +kernel_sys_ioctl (fd,TCSETSF , (long )&termios); +kernel_sys_read (fd, &c,1 ); termios.c_lflag |=ICANON ; -sys_ioctl (fd,TCSETSF , (long )&termios); -sys_close (fd); +kernel_sys_ioctl (fd,TCSETSF , (long )&termios); +kernel_sys_close (fd); } }#endif
@@ -417,6 +418,6 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount ("dev" ); -sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); -sys_chroot ((const char __user __force *)"." ); +kernel_sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +kernel_sys_chroot ("." ); }
init/do_mounts_initrd.c +25 -23
108 lines not on this page · raw message
init/do_mounts_md.c +15 -14
@@ -2,6 +2,7 @@#include <linux/raid/md_u.h> #include <linux/raid/md_p.h> +#include "sys-wrapper.h" #include "do_mounts.h" /*
@@ -170,17 +171,17 @@ static void __init md_setup_drive(void) partitioned ?"_d" :"" , minor, md_setup_args[ent].device_names); - fd =sys_open (name,0 ,0 ); + fd =kernel_sys_open (name,0 ,0 );if (fd <0 ) {printk (KERN_ERR "md: open failed - cannot start " "array %s\n" , name);continue ; } -if (sys_ioctl (fd,SET_ARRAY_INFO ,0 ) == -EBUSY ) { +if (kernel_sys_ioctl (fd,SET_ARRAY_INFO ,0 ) == -EBUSY ) {printk (KERN_WARNING "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n" , minor); -sys_close (fd); +kernel_sys_close (fd);continue ; }
@@ -199,7 +200,7 @@ static void __init md_setup_drive(void) ainfo.state = (1 <<MD_SB_CLEAN ); ainfo.layout =0 ; ainfo.chunk_size = md_setup_args[ent].chunk; - err =sys_ioctl (fd,SET_ARRAY_INFO , (long )&ainfo); + err =kernel_sys_ioctl (fd,SET_ARRAY_INFO , (long )&ainfo);for (i =0 ; !err && i <=MD_SB_DISKS ; i++) { dev = devices[i];if (!dev)
@@ -209,7 +210,7 @@ static void __init md_setup_drive(void) dinfo.state = (1 <<MD_DISK_ACTIVE )|(1 <<MD_DISK_SYNC ); dinfo.major =MAJOR (dev); dinfo.minor =MINOR (dev); - err =sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); + err =kernel_sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); } }else {/* persistent */
@@ -219,11 +220,11 @@ static void __init md_setup_drive(void)break ; dinfo.major =MAJOR (dev); dinfo.minor =MINOR (dev); -sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); +kernel_sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); } }if (!err) - err =sys_ioctl (fd,RUN_ARRAY ,0 ); + err =kernel_sys_ioctl (fd,RUN_ARRAY ,0 );if (err)printk (KERN_WARNING "md: starting md%d failed\n" , minor);else {
@@ -232,11 +233,11 @@ static void __init md_setup_drive(void)* boot a kernel with devfs compiled in from partitioned md * array without it */ -sys_close (fd); - fd =sys_open (name,0 ,0 ); -sys_ioctl (fd,BLKRRPART ,0 ); +kernel_sys_close (fd); + fd =kernel_sys_open (name,0 ,0 ); +kernel_sys_ioctl (fd,BLKRRPART ,0 ); } -sys_close (fd); +kernel_sys_close (fd); } }
@@ -283,10 +284,10 @@ static void __init autodetect_raid(void)wait_for_device_probe (); - fd =sys_open ((const char __user __force *)"/dev/md0" ,0 ,0 ); + fd =kernel_sys_open ("/dev/md0" ,0 ,0 );if (fd >=0 ) { -sys_ioctl (fd,RAID_AUTORUN , raid_autopart); -sys_close (fd); +kernel_sys_ioctl (fd,RAID_AUTORUN , raid_autopart); +kernel_sys_close (fd); } }
init/do_mounts_rd.c +20 -19
@@ -9,8 +9,9 @@#include <linux/string.h> #include <linux/slab.h> -#include "do_mounts.h" #include "../fs/squashfs/squashfs_fs.h" +#include "sys-wrapper.h" +#include "do_mounts.h" #include <linux/decompress/generic.h>
@@ -76,8 +77,8 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)/* * Read block 0 to test for compressed kernel */ -sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); -sys_read (fd, buf, size); +kernel_sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); +kernel_sys_read (fd, buf, size); *decompressor =decompress_method (buf, size, &compress_name);if (compress_name) {
@@ -122,8 +123,8 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)/* * Read block 1 to test for minix and ext2 superblock */ -sys_lseek (fd, (start_block+1 ) *BLOCK_SIZE ,0 ); -sys_read (fd, buf, size); +kernel_sys_lseek (fd, (start_block+1 ) *BLOCK_SIZE ,0 ); +kernel_sys_read (fd, buf, size);/* Try minix */ if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
@@ -150,7 +151,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) start_block); done: -sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); +kernel_sys_lseek (fd, start_block *BLOCK_SIZE ,0 );kfree (buf);return nblocks; }
@@ -168,11 +169,11 @@ int __init rd_load_image(char *from)char rotator[4 ] = {'|' ,'/' ,'-' ,'\\' };#endif - out_fd =sys_open ((const char __user __force *)"/dev/ram" ,O_RDWR ,0 ); + out_fd =kernel_sys_open ("/dev/ram" ,O_RDWR ,0 );if (out_fd <0 ) goto out; - in_fd =sys_open (from,O_RDONLY ,0 ); + in_fd =kernel_sys_open (from,O_RDONLY ,0 );if (in_fd <0 ) goto noclose_input;
@@ -197,7 +198,7 @@ int __init rd_load_image(char *from)* silly to use anything else, so make sure to use 1KiB * blocksize while generating ext2fs ramdisk-images. */ -if (sys_ioctl (out_fd,BLKGETSIZE , (unsigned long )&rd_blocks) <0 ) +if (kernel_sys_ioctl (out_fd,BLKGETSIZE , (unsigned long )&rd_blocks) <0 ) rd_blocks =0 ;else rd_blocks >>=1 ;
@@ -211,7 +212,7 @@ int __init rd_load_image(char *from)/* * OK, time to copy in the data */ -if (sys_ioctl (in_fd,BLKGETSIZE , (unsigned long )&devblocks) <0 ) +if (kernel_sys_ioctl (in_fd,BLKGETSIZE , (unsigned long )&devblocks) <0 ) devblocks =0 ;else devblocks >>=1 ;
@@ -236,20 +237,20 @@ int __init rd_load_image(char *from)if (i && (i % devblocks ==0 )) {printk ("done disk #%d.\n" , disk++); rotate =0 ; -if (sys_close (in_fd)) { +if (kernel_sys_close (in_fd)) {printk ("Error closing the disk.\n" ); goto noclose_input; }change_floppy ("disk #%d" , disk); - in_fd =sys_open (from,O_RDONLY ,0 ); + in_fd =kernel_sys_open (from,O_RDONLY ,0 );if (in_fd <0 ) {printk ("Error opening disk.\n" ); goto noclose_input; }printk ("Loading disk #%d... " , disk); } -sys_read (in_fd, buf,BLOCK_SIZE ); -sys_write (out_fd, buf,BLOCK_SIZE ); +kernel_sys_read (in_fd, buf,BLOCK_SIZE ); +kernel_sys_write (out_fd, buf,BLOCK_SIZE );#if !defined(CONFIG_S390 ) && !defined(CONFIG_PPC_ISERIES )if (!(i %16 )) {printk ("%c\b" , rotator[rotate &0x3 ]);
@@ -262,12 +263,12 @@ int __init rd_load_image(char *from) successful_load: res =1 ; done: -sys_close (in_fd); +kernel_sys_close (in_fd); noclose_input: -sys_close (out_fd); +kernel_sys_close (out_fd); out:kfree (buf); -sys_unlink ((const char __user __force *)"/dev/ram" ); +kernel_sys_unlink ("/dev/ram" );return res; }
@@ -286,7 +287,7 @@ static int crd_infd, crd_outfd;static int __init compr_fill (void *buf,unsigned int len) { -int r =sys_read (crd_infd, buf, len); +int r =kernel_sys_read (crd_infd, buf, len);if (r <0 )printk (KERN_ERR "RAMDISK: error while reading compressed data" );else if (r ==0 )
@@ -296,7 +297,7 @@ static int __init compr_fill(void *buf, unsigned int len)static int __init compr_flush (void *window,unsigned int outcnt) { -int written =sys_write (crd_outfd, window, outcnt); +int written =kernel_sys_write (crd_outfd, window, outcnt);if (written != outcnt) {if (decompress_error ==0 ) printk(KERN_ERR
init/initramfs.c +33 -31
161 lines not on this page · raw message
init/main.c +7 -5
@@ -6,7 +6,7 @@* GK 2/5/95 - Changed to support mounting root fs via NFS * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 -* Simplified starting of init: Michael A. Griffith <[email protected]> +* Simplified starting of init: Michael A. Griffith <[email protected]> */ #include <linux/types.h>
@@ -79,6 +79,8 @@#include <asm/smp.h> #endif +#include "sys-wrapper.h" +static int kernel_init (void *);extern void init_IRQ (void );
@@ -893,11 +895,11 @@ static int __init kernel_init(void * unused)do_basic_setup ();/* Open the /dev/console on the rootfs, this should never fail */ -if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 ) +if (kernel_sys_open ("/dev/console" ,O_RDWR ,0 ) <0 )printk (KERN_WARNING "Warning: unable to open an initial console.\n" ); - (void )sys_dup (0 ); - (void )sys_dup (0 ); + (void )kernel_sys_dup (0 ); + (void )kernel_sys_dup (0 );/* * check if there is an early userspace init. If yes, let it do all * the work
@@ -906,7 +908,7 @@ static int __init kernel_init(void * unused)if (!ramdisk_execute_command) ramdisk_execute_command ="/init" ; -if (sys_access ((const char __user *) ramdisk_execute_command,0 ) !=0 ) { +if (kernel_sys_access (ramdisk_execute_command,0 ) !=0 ) { ramdisk_execute_command =NULL ;prepare_namespace (); }
init/noinitramfs.c +7 -5
@@ -22,6 +22,8 @@#include <linux/kdev_t.h> #include <linux/syscalls.h> +#include "sys-wrapper.h" +/* * Create a simple rootfs that is similar to the default initramfs */
@@ -29,17 +31,17 @@ static int __init default_rootfs(void) {int err; - err =sys_mkdir ((const char __user __force *)"/dev" ,0755 ); + err =kernel_sys_mkdir ("/dev" ,0755 );if (err <0 ) goto out; - err =sys_mknod ((const char __user __force *)"/dev/console" , -S_IFCHR |S_IRUSR |S_IWUSR , -new_encode_dev (MKDEV (5 ,1 ))); + err =kernel_sys_mknod ("/dev/console" , +S_IFCHR |S_IRUSR |S_IWUSR , +new_encode_dev (MKDEV (5 ,1 )));if (err <0 ) goto out; - err =sys_mkdir ((const char __user __force *)"/root" ,0700 ); + err =kernel_sys_mkdir ("/root" ,0700 );if (err <0 ) goto out;
Signature · 1 line
1.7.2.2
Re: [PATCH v4 2/2] init: use kernel_sys_* wrappers instead of syscall
I missed fixing commit log. Please use below instead. Thanks.
Quoted 1 line
From
c8653cca467a89b4d89dd42ce6f7fa966f9cca3bMon Sep 17 00:00:00 2001
From: Namhyung Kim <[email protected]>
Date: Tue, 31 Aug 2010 01:51:10 +0900
Subject: [PATCH v4 RESEND 2/2] init: use kernel_sys_* wrappers instead of syscall
replace direct syscall invocations to its wrapper functions defined in init/sys-wrapper.h. This can remove following sparse warnings:
init/main.c:896:23: warning: cast adds address space to expression (<asn:1>)
...
init/do_mounts.c:220:29: warning: incorrect type in argument 1 (different address spaces)
init/do_mounts.c:220:29: expected char [noderef] <asn:1>*dev_name
init/do_mounts.c:220:29: got char *name
...
--- init/do_mounts.c | 29 +++++++++++---------- init/do_mounts_initrd.c | 48 ++++++++++++++++++----------------- init/do_mounts_md.c | 29 +++++++++++---------- init/do_mounts_rd.c | 39 ++++++++++++++-------------- init/initramfs.c | 64 ++++++++++++++++++++++++---------------------- init/main.c | 12 +++++--- init/noinitramfs.c | 12 +++++--- 7 files changed, 122 insertions(+), 111 deletions(-)
init/do_mounts.c +15 -14
@@ -21,6 +21,7 @@#include <linux/nfs_fs_sb.h> #include <linux/nfs_mount.h> +#include "sys-wrapper.h" #include "do_mounts.h" int __initdata rd_doload;/* 1 = load RAM disk, 0 = don't load */
@@ -217,11 +218,11 @@ static void __init get_fs_names(char *page)static int __init do_mount_root (char *name,char *fs,int flags,void *data) { -int err =sys_mount (name,"/root" , fs, flags, data); +int err =kernel_sys_mount (name,"/root" , fs, flags, data);if (err)return err; -sys_chdir ((const char __user __force *)"/root" ); +kernel_sys_chdir ("/root" );ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev; printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n", current->fs->pwd.mnt->mnt_sb->s_type->name,
@@ -287,7 +288,7 @@ retry: out:putname (fs_names); } - +#ifdef CONFIG_ROOT_NFS static int __init mount_nfs_root (void ) {
@@ -312,21 +313,21 @@ void __init change_floppy(char *fmt, ...)va_start (args, fmt);vsprintf (buf, fmt, args);va_end (args); - fd =sys_open ("/dev/root" ,O_RDWR |O_NDELAY ,0 ); + fd =kernel_sys_open ("/dev/root" ,O_RDWR |O_NDELAY ,0 );if (fd >=0 ) { -sys_ioctl (fd,FDEJECT ,0 ); -sys_close (fd); +kernel_sys_ioctl (fd,FDEJECT ,0 ); +kernel_sys_close (fd); }printk (KERN_NOTICE "VFS: Insert %s and press ENTER\n" , buf); - fd =sys_open ("/dev/console" ,O_RDWR ,0 ); + fd =kernel_sys_open ("/dev/console" ,O_RDWR ,0 );if (fd >=0 ) { -sys_ioctl (fd,TCGETS , (long )&termios); +kernel_sys_ioctl (fd,TCGETS , (long )&termios); termios.c_lflag &= ~ICANON ; -sys_ioctl (fd,TCSETSF , (long )&termios); -sys_read (fd, &c,1 ); +kernel_sys_ioctl (fd,TCSETSF , (long )&termios); +kernel_sys_read (fd, &c,1 ); termios.c_lflag |=ICANON ; -sys_ioctl (fd,TCSETSF , (long )&termios); -sys_close (fd); +kernel_sys_ioctl (fd,TCSETSF , (long )&termios); +kernel_sys_close (fd); } }#endif
@@ -417,6 +418,6 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount ("dev" ); -sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); -sys_chroot ((const char __user __force *)"." ); +kernel_sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +kernel_sys_chroot ("." ); }
init/do_mounts_initrd.c +25 -23
108 lines not on this page · raw message
init/do_mounts_md.c +15 -14
@@ -2,6 +2,7 @@#include <linux/raid/md_u.h> #include <linux/raid/md_p.h> +#include "sys-wrapper.h" #include "do_mounts.h" /*
@@ -170,17 +171,17 @@ static void __init md_setup_drive(void) partitioned ?"_d" :"" , minor, md_setup_args[ent].device_names); - fd =sys_open (name,0 ,0 ); + fd =kernel_sys_open (name,0 ,0 );if (fd <0 ) {printk (KERN_ERR "md: open failed - cannot start " "array %s\n" , name);continue ; } -if (sys_ioctl (fd,SET_ARRAY_INFO ,0 ) == -EBUSY ) { +if (kernel_sys_ioctl (fd,SET_ARRAY_INFO ,0 ) == -EBUSY ) {printk (KERN_WARNING "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n" , minor); -sys_close (fd); +kernel_sys_close (fd);continue ; }
@@ -199,7 +200,7 @@ static void __init md_setup_drive(void) ainfo.state = (1 <<MD_SB_CLEAN ); ainfo.layout =0 ; ainfo.chunk_size = md_setup_args[ent].chunk; - err =sys_ioctl (fd,SET_ARRAY_INFO , (long )&ainfo); + err =kernel_sys_ioctl (fd,SET_ARRAY_INFO , (long )&ainfo);for (i =0 ; !err && i <=MD_SB_DISKS ; i++) { dev = devices[i];if (!dev)
@@ -209,7 +210,7 @@ static void __init md_setup_drive(void) dinfo.state = (1 <<MD_DISK_ACTIVE )|(1 <<MD_DISK_SYNC ); dinfo.major =MAJOR (dev); dinfo.minor =MINOR (dev); - err =sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); + err =kernel_sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); } }else {/* persistent */
@@ -219,11 +220,11 @@ static void __init md_setup_drive(void)break ; dinfo.major =MAJOR (dev); dinfo.minor =MINOR (dev); -sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); +kernel_sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); } }if (!err) - err =sys_ioctl (fd,RUN_ARRAY ,0 ); + err =kernel_sys_ioctl (fd,RUN_ARRAY ,0 );if (err)printk (KERN_WARNING "md: starting md%d failed\n" , minor);else {
@@ -232,11 +233,11 @@ static void __init md_setup_drive(void)* boot a kernel with devfs compiled in from partitioned md * array without it */ -sys_close (fd); - fd =sys_open (name,0 ,0 ); -sys_ioctl (fd,BLKRRPART ,0 ); +kernel_sys_close (fd); + fd =kernel_sys_open (name,0 ,0 ); +kernel_sys_ioctl (fd,BLKRRPART ,0 ); } -sys_close (fd); +kernel_sys_close (fd); } }
@@ -283,10 +284,10 @@ static void __init autodetect_raid(void)wait_for_device_probe (); - fd =sys_open ((const char __user __force *)"/dev/md0" ,0 ,0 ); + fd =kernel_sys_open ("/dev/md0" ,0 ,0 );if (fd >=0 ) { -sys_ioctl (fd,RAID_AUTORUN , raid_autopart); -sys_close (fd); +kernel_sys_ioctl (fd,RAID_AUTORUN , raid_autopart); +kernel_sys_close (fd); } }
init/do_mounts_rd.c +20 -19
@@ -9,8 +9,9 @@#include <linux/string.h> #include <linux/slab.h> -#include "do_mounts.h" #include "../fs/squashfs/squashfs_fs.h" +#include "sys-wrapper.h" +#include "do_mounts.h" #include <linux/decompress/generic.h>
@@ -76,8 +77,8 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)/* * Read block 0 to test for compressed kernel */ -sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); -sys_read (fd, buf, size); +kernel_sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); +kernel_sys_read (fd, buf, size); *decompressor =decompress_method (buf, size, &compress_name);if (compress_name) {
@@ -122,8 +123,8 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)/* * Read block 1 to test for minix and ext2 superblock */ -sys_lseek (fd, (start_block+1 ) *BLOCK_SIZE ,0 ); -sys_read (fd, buf, size); +kernel_sys_lseek (fd, (start_block+1 ) *BLOCK_SIZE ,0 ); +kernel_sys_read (fd, buf, size);/* Try minix */ if (minixsb->s_magic == MINIX_SUPER_MAGIC ||
@@ -150,7 +151,7 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) start_block); done: -sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); +kernel_sys_lseek (fd, start_block *BLOCK_SIZE ,0 );kfree (buf);return nblocks; }
@@ -168,11 +169,11 @@ int __init rd_load_image(char *from)char rotator[4 ] = {'|' ,'/' ,'-' ,'\\' };#endif - out_fd =sys_open ((const char __user __force *)"/dev/ram" ,O_RDWR ,0 ); + out_fd =kernel_sys_open ("/dev/ram" ,O_RDWR ,0 );if (out_fd <0 ) goto out; - in_fd =sys_open (from,O_RDONLY ,0 ); + in_fd =kernel_sys_open (from,O_RDONLY ,0 );if (in_fd <0 ) goto noclose_input;
@@ -197,7 +198,7 @@ int __init rd_load_image(char *from)* silly to use anything else, so make sure to use 1KiB * blocksize while generating ext2fs ramdisk-images. */ -if (sys_ioctl (out_fd,BLKGETSIZE , (unsigned long )&rd_blocks) <0 ) +if (kernel_sys_ioctl (out_fd,BLKGETSIZE , (unsigned long )&rd_blocks) <0 ) rd_blocks =0 ;else rd_blocks >>=1 ;
@@ -211,7 +212,7 @@ int __init rd_load_image(char *from)/* * OK, time to copy in the data */ -if (sys_ioctl (in_fd,BLKGETSIZE , (unsigned long )&devblocks) <0 ) +if (kernel_sys_ioctl (in_fd,BLKGETSIZE , (unsigned long )&devblocks) <0 ) devblocks =0 ;else devblocks >>=1 ;
@@ -236,20 +237,20 @@ int __init rd_load_image(char *from)if (i && (i % devblocks ==0 )) {printk ("done disk #%d.\n" , disk++); rotate =0 ; -if (sys_close (in_fd)) { +if (kernel_sys_close (in_fd)) {printk ("Error closing the disk.\n" ); goto noclose_input; }change_floppy ("disk #%d" , disk); - in_fd =sys_open (from,O_RDONLY ,0 ); + in_fd =kernel_sys_open (from,O_RDONLY ,0 );if (in_fd <0 ) {printk ("Error opening disk.\n" ); goto noclose_input; }printk ("Loading disk #%d... " , disk); } -sys_read (in_fd, buf,BLOCK_SIZE ); -sys_write (out_fd, buf,BLOCK_SIZE ); +kernel_sys_read (in_fd, buf,BLOCK_SIZE ); +kernel_sys_write (out_fd, buf,BLOCK_SIZE );#if !defined(CONFIG_S390 ) && !defined(CONFIG_PPC_ISERIES )if (!(i %16 )) {printk ("%c\b" , rotator[rotate &0x3 ]);
@@ -262,12 +263,12 @@ int __init rd_load_image(char *from) successful_load: res =1 ; done: -sys_close (in_fd); +kernel_sys_close (in_fd); noclose_input: -sys_close (out_fd); +kernel_sys_close (out_fd); out:kfree (buf); -sys_unlink ((const char __user __force *)"/dev/ram" ); +kernel_sys_unlink ("/dev/ram" );return res; }
@@ -286,7 +287,7 @@ static int crd_infd, crd_outfd;static int __init compr_fill (void *buf,unsigned int len) { -int r =sys_read (crd_infd, buf, len); +int r =kernel_sys_read (crd_infd, buf, len);if (r <0 )printk (KERN_ERR "RAMDISK: error while reading compressed data" );else if (r ==0 )
@@ -296,7 +297,7 @@ static int __init compr_fill(void *buf, unsigned int len)static int __init compr_flush (void *window,unsigned int outcnt) { -int written =sys_write (crd_outfd, window, outcnt); +int written =kernel_sys_write (crd_outfd, window, outcnt);if (written != outcnt) {if (decompress_error ==0 ) printk(KERN_ERR
init/initramfs.c +33 -31
161 lines not on this page · raw message
init/main.c +7 -5
@@ -6,7 +6,7 @@* GK 2/5/95 - Changed to support mounting root fs via NFS * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96 * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96 -* Simplified starting of init: Michael A. Griffith <[email protected]> +* Simplified starting of init: Michael A. Griffith <[email protected]> */ #include <linux/types.h>
@@ -79,6 +79,8 @@#include <asm/smp.h> #endif +#include "sys-wrapper.h" +static int kernel_init (void *);extern void init_IRQ (void );
@@ -893,11 +895,11 @@ static int __init kernel_init(void * unused)do_basic_setup ();/* Open the /dev/console on the rootfs, this should never fail */ -if (sys_open ((const char __user *)"/dev/console" ,O_RDWR ,0 ) <0 ) +if (kernel_sys_open ("/dev/console" ,O_RDWR ,0 ) <0 )printk (KERN_WARNING "Warning: unable to open an initial console.\n" ); - (void )sys_dup (0 ); - (void )sys_dup (0 ); + (void )kernel_sys_dup (0 ); + (void )kernel_sys_dup (0 );/* * check if there is an early userspace init. If yes, let it do all * the work
@@ -906,7 +908,7 @@ static int __init kernel_init(void * unused)if (!ramdisk_execute_command) ramdisk_execute_command ="/init" ; -if (sys_access ((const char __user *) ramdisk_execute_command,0 ) !=0 ) { +if (kernel_sys_access (ramdisk_execute_command,0 ) !=0 ) { ramdisk_execute_command =NULL ;prepare_namespace (); }
init/noinitramfs.c +7 -5
@@ -22,6 +22,8 @@#include <linux/kdev_t.h> #include <linux/syscalls.h> +#include "sys-wrapper.h" +/* * Create a simple rootfs that is similar to the default initramfs */
@@ -29,17 +31,17 @@ static int __init default_rootfs(void) {int err; - err =sys_mkdir ((const char __user __force *)"/dev" ,0755 ); + err =kernel_sys_mkdir ("/dev" ,0755 );if (err <0 ) goto out; - err =sys_mknod ((const char __user __force *)"/dev/console" , -S_IFCHR |S_IRUSR |S_IWUSR , -new_encode_dev (MKDEV (5 ,1 ))); + err =kernel_sys_mknod ("/dev/console" , +S_IFCHR |S_IRUSR |S_IWUSR , +new_encode_dev (MKDEV (5 ,1 )));if (err <0 ) goto out; - err =sys_mkdir ((const char __user __force *)"/root" ,0700 ); + err =kernel_sys_mkdir ("/root" ,0700 );if (err <0 ) goto out;
Signature · 1 line
1.7.2.2