init cleanups
v3 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 kern_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.
Any comments would be welcomed.
Thanks.
[1] http://lkml.org/lkml/2010/8/18/157
---
* 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 | 37 ++++---- init/initramfs.c | 61 +++++++------ init/main.c | 9 +- init/noinitramfs.c | 10 +- init/sys-wrapper.h | 230 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 345 insertions(+), 108 deletions(-) create mode 100644 init/sys-wrapper.h
--
1.7.2.2
PATCH v3 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 | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 230 insertions(+), 0 deletions(-) create mode 100644 init/sys-wrapper.h
init/sys-wrapper.h new file +230 -0
@@ -0,0 +1,230 @@ +/* +* init/sys-wrapper.h +* +* Copyright (C) 2010 Namhyung Kim <[email protected]> +* +* wrappers for various syscalls for use in the init code +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/ + +#include <linux/fs.h> +#include <linux/types.h> +#include <linux/fcntl.h> +#include <linux/dirent.h> +#include <linux/syscalls.h> + + +#define kern_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 kern_sys_mount (char *dev_name,char *dir_name,char *type, +unsigned long flags,void *data) +{ +return kern_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 kern_sys_umount (char *name,int flags) +{ +return kern_sys_call (sys_umount, + (char __user __force *) name, flags); +} + +static inline int kern_sys_chroot (const char *pathname) +{ +return kern_sys_call (sys_chroot, + (const char __user __force *) pathname); +} + +static inline int kern_sys_link (const char *oldname,const char *newname) +{ +return kern_sys_call (sys_link, + (const char __user __force *) oldname, + (const char __user __force *) newname); +} + +static inline int kern_sys_unlink (const char *pathname) +{ +return kern_sys_call (sys_unlink, + (const char __user __force *) pathname); +} + +static inline int kern_sys_newlstat (const char *filename, +struct stat *statbuf) +{ +return kern_sys_call (sys_newlstat, + (const char __user __force *) filename, + (struct stat __user __force *) statbuf); +} + +static inline int kern_sys_mkdir (const char *pathname,int mode) +{ +return kern_sys_call (sys_mkdir, + (const char __user __force *) pathname, mode); +} + +static inline int kern_sys_rmdir (const char *pathname) +{ +return kern_sys_call (sys_rmdir, + (const char __user __force *) pathname); +} + +static inline int kern_sys_chdir (const char *pathname) +{ +return kern_sys_call (sys_chdir, + (const char __user __force *) pathname); +} + +static inline int kern_sys_mknod (const char *filename,int mode,unsigned dev) +{ +return kern_sys_call (sys_mknod, + (const char __user __force *) filename, + mode, dev); +} + +static inline int kern_sys_chown (const char *filename,uid_t user,gid_t group) +{ +return kern_sys_call (sys_chown, + (const char __user __force *) filename, + user, group); +} + +static inline int kern_sys_chmod (const char *filename,mode_t mode) +{ +return kern_sys_call (sys_chmod, + (const char __user __force *) filename, mode); +} + +static inline int kern_sys_open (const char *filename,int flags,int mode) +{ +return kern_sys_call (sys_open, + (const char __user __force *) filename, + flags, mode); +} + +static inline int kern_sys_fchown (unsigned int fd,uid_t user,gid_t group) +{ +return sys_fchown (fd, user, group); +} + +static inline int kern_sys_fchmod (unsigned int fd,mode_t mode) +{ +return sys_fchmod (fd, mode); +} + +static inline int kern_sys_fchdir (unsigned int fd) +{ +return sys_fchdir (fd); +} + +static inline int kern_sys_ftruncate (unsigned int fd,unsigned long length) +{ +return sys_ftruncate (fd, length); +} + +static inline int kern_sys_read (unsigned int fd,char *buf,size_t count) +{ +return kern_sys_call (sys_read, + fd, (char __user __force *) buf, count); +} + +static inline int kern_sys_write (unsigned int fd,const char *buf, +size_t count) +{ +return kern_sys_call (sys_write, + fd, (const char __user __force *) buf, count); +} + +static inline int kern_sys_lseek (unsigned int fd,off_t offset, +unsigned int origin) +{ +return sys_lseek (fd, offset, origin); +} + +static inline int kern_sys_ioctl (unsigned int fd,unsigned int cmd, +unsigned long arg) +{ +return sys_ioctl (fd, cmd, arg); +} + +static inline int kern_sys_dup (unsigned int fd) +{ +return sys_dup (fd); +} + +static inline int kern_sys_close (unsigned int fd) +{ +return sys_close (fd); +} + +static inline int kern_sys_symlink (const char *oldname,const char *newname) +{ +return kern_sys_call (sys_symlink, + (const char __user __force *) oldname, + (const char __user __force *) newname); +} + +static inline int kern_sys_lchown (const char *filename,uid_t user, +gid_t group) +{ +return kern_sys_call (sys_lchown, + (const char __user __force *) filename, + user, group); +} + +static inline int kern_sys_getdents64 (unsigned int fd, +struct linux_dirent64 *dirent, +unsigned int count) +{ +return kern_sys_call (sys_getdents64, + fd, + (struct linux_dirent64 __user __force *) dirent, + count); +} + +static inline int kern_sys_access (const char *filename,int mode) +{ +return kern_sys_call (sys_access, + (const char __user __force *) filename, mode); +} + +static inline int kern_sys_setsid (void ) +{ +return sys_setsid (); +} + +static inline int kern_sys_wait4 (pid_t upid,int *stat_addr,int options, +struct rusage *ru) +{ +return kern_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 v3 1/2] init: add sys-wrapper.h
Hi Namhyung Kim.
Some very basic comments.
Quoted 17 lines · Namhyung Kim
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.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- init/sys-wrapper.h | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 230 insertions(+), 0 deletions(-) create mode 100644 init/sys-wrapper.hinit/sys-wrapper.h new file +0
-0
init/sys-wrapper.h line 2
Quoted 2 lines
init/sys-wrapper.h new file +2
-0@@ -0,0 +1,230 @@ +/* +* init/sys-wrapper.h
Drop the filename - it has a tendency to get outdated.
Quoted 10 lines
init/sys-wrapper.h new file +10
-0+* +* Copyright (C) 2010 Namhyung Kim <[email protected]> +* +* wrappers for various syscalls for use in the init code +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation. +*
init/sys-wrapper.h line 22
Quoted 10 lines
init/sys-wrapper.h new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/
Drop the license text. The kernel is covered by GPL v2 anyway.
init/sys-wrapper.h line 29
Quoted 7 lines
init/sys-wrapper.h new file +7
-0+ +#include <linux/fs.h> +#include <linux/types.h> +#include <linux/fcntl.h> +#include <linux/dirent.h> +#include <linux/syscalls.h> +
I usually see the inverse christmas tree recommended, that is the longest name first.
init/sys-wrapper.h line 40
Quoted 11 lines
init/sys-wrapper.h new file +11
-0+ +#define kern_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; \ +}) +
Personal preference...
Replace kern_ with kernel_ all over.
init/sys-wrapper.h line 51
Quoted 11 lines
init/sys-wrapper.h new file +11
-0+static inline int kern_sys_mount (char *dev_name,char *dir_name,char *type, +unsigned long flags,void *data) +{ +return kern_sys_call (sys_mount, + (char __user __force *) dev_name, + (char __user __force *) dir_name, + (char __user __force *) type, + flags, + (void __user __force *) data); +} +
I have not tried to investigate the sparse annotations. But I wonder whay strings are "(char __user __force *)". Is this because the sting usually come from userspace?
Sam
Re: [PATCH v3 1/2] init: add sys-wrapper.h
Quoted 4 lines · Sam Ravnborg
Hi Namhyung Kim.
Some very basic comments.
Hi,
Thanks for your comments.
Quoted 44 lines · Namhyung Kim
Quoted 17 lines
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.Suggested-by Arnd Bergmann <[email protected]>Signed-off-by Namhyung Kim <[email protected]>---
init/sys-wrapper.h | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++++1 files changed, 230 insertions(+), 0 deletions(-)create mode 100644
init/sys-wrapper.hinit/sys-wrapper.h new file +0
-0init/sys-wrapper.h line 2
Quoted 2 lines
init/sys-wrapper.h new file +2
-0@@ -0,0 +1,230 @@ +/* +* init/sys-wrapper.h Drop the filename - it has a tendency to get outdated.
Quoted 10 lines
init/sys-wrapper.h new file +10
-0+* +* Copyright (C) 2010 Namhyung Kim <[email protected]> +* +* wrappers for various syscalls for use in the init code +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation.dummy +* init/sys-wrapper.h line 22
Quoted 10 lines
init/sys-wrapper.h new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/ Drop the license text. The kernel is covered by GPL v2 anyway.
Quoted 10 lines
init/sys-wrapper.h line 29
Quoted 7 lines
init/sys-wrapper.h new file +7
-0+ +#include <linux/fs.h> +#include <linux/types.h> +#include <linux/fcntl.h> +#include <linux/dirent.h> +#include <linux/syscalls.h> +I usually see the inverse christmas tree recommended, that is the longest name first.
OK. Then, how about this?
(I added <asm/uaccess.h> and removed <linux/fcntl.h> because I think it is more appropriate.)
/*
* 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/dirent.h>
#include <linux/types.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
Quoted 6 lines
Quoted 6 lines
init/sys-wrapper.h new file +6
-0+ +#define kern_sys_call (call, ...) \ +({ \ + long result; \ + mm_segment_t old_fs = get_fs(); \ + set_fs(KERNEL_DS); \
Quoted 9 lines
init/sys-wrapper.h line 40
Quoted 5 lines
init/sys-wrapper.h new file +5
-0+ result = call(__VA_ARGS__); \ + set_fs(old_fs); \ + result; \ +}) +Personal preference...
Replacekern_withkernel_all over.
Is this just your preference or general tendency?
Quoted 7 lines
Quoted 7 lines
init/sys-wrapper.h new file +7
-0+static inline int kern_sys_mount (char *dev_name,char *dir_name,char *type, + unsigned long flags, void *data) +{ + return kern_sys_call(sys_mount, + (char __user __force *) dev_name, + (char __user __force *) dir_name, + (char __user __force *) type,
Quoted 9 lines
init/sys-wrapper.h line 51
Quoted 4 lines
init/sys-wrapper.h new file +4
-0+ flags, + (void __user __force *) data); +} +I have not tried to investigate the sparse annotations. But I wonder whay strings are "(char
__user__force*)". Is this because the sting usually come from userspace?
No, usual strings are in kernel space but syscall requires its arguments to be __user pointers so we have to convert __force.
Signature · 2 lines
Regards, Namhyung Kim
Re: [PATCH v3 1/2] init: add sys-wrapper.h
Quoted 9 lines
/*
* wrappers for various syscalls for use in the init code *
* Copyright (C) 2010 Namhyung Kim <[email protected]> *
* This file is released under the GPLv2.
*/
Quoted 7 lines
#include <
linux/syscalls.h>
#include <linux/dirent.h>
#include <linux/types.h>
#include <linux/fs.h>#include <
asm/uaccess.h>
Good.
Except that we usually recommend to include files from include/linux if thye exist rather than asm/xxx
So use: #include <linux/uaccess.h>
Quoted 17 lines
Quoted 16 lines
init/sys-wrapper.h line 40
Quoted 12 lines
init/sys-wrapper.h new file +11
-0+ +#define kern_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; \ +}) +Personal preference...
Replacekern_withkernel_all over.
Quoted 1 line
Is this just your preference or general tendency?
I asked git:
$ git grep kern_ | wc -l 962 $ git grep kernel_ | wc -l 6361
There seems to be preference for kernel_
Sam
Re: [PATCH v3 1/2] init: add sys-wrapper.h
Quoted 14 lines · Sam Ravnborg
Quoted 14 lines
/*
* 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/dirent.h>
#include <linux/types.h>
#include <linux/fs.h>
Quoted 9 lines
Quoted 2 lines
#include <
asm/uaccess.h>Good.
Except that we usually recommend to include files frominclude/linuxif thye exist rather than asm/xxxSo use: #include <
linux/uaccess.h>
OK. No problem. :-)
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
init/sys-wrapper.h line 40
Quoted 13 lines
init/sys-wrapper.h new file +11
-0+ +#define kern_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; \ +}) +Personal preference...
Replacekern_withkernel_all over.
Quoted 9 lines
Quoted 1 line
Is this just your preference or general tendency?
I asked git:
$ git grep kern_ | wc -l 962 $ git grep kernel_ | wc -l 6361There seems to be preference for
kernel_
I see. Will change it.
Thanks.
Signature · 2 lines
Regards, Namhyung Kim
PATCH v3 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
--- init/do_mounts.c | 29 +++++++++++---------- init/do_mounts_initrd.c | 48 +++++++++++++++++++----------------- init/do_mounts_md.c | 29 +++++++++++---------- init/do_mounts_rd.c | 37 ++++++++++++++-------------- init/initramfs.c | 61 ++++++++++++++++++++++++----------------------- init/main.c | 9 ++++--- init/noinitramfs.c | 10 ++++---- 7 files changed, 115 insertions(+), 108 deletions(-)
init/do_mounts.c +15 -14
@@ -22,6 +22,7 @@#include <linux/nfs_mount.h> #include "do_mounts.h" +#include "sys-wrapper.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 =kern_sys_mount (name,"/root" , fs, flags, data);if (err)return err; -sys_chdir ((const char __user __force *)"/root" ); +kern_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 =kern_sys_open ("/dev/root" ,O_RDWR |O_NDELAY ,0 );if (fd >=0 ) { -sys_ioctl (fd,FDEJECT ,0 ); -sys_close (fd); +kern_sys_ioctl (fd,FDEJECT ,0 ); +kern_sys_close (fd); }printk (KERN_NOTICE "VFS: Insert %s and press ENTER\n" , buf); - fd =sys_open ("/dev/console" ,O_RDWR ,0 ); + fd =kern_sys_open ("/dev/console" ,O_RDWR ,0 );if (fd >=0 ) { -sys_ioctl (fd,TCGETS , (long )&termios); +kern_sys_ioctl (fd,TCGETS , (long )&termios); termios.c_lflag &= ~ICANON ; -sys_ioctl (fd,TCSETSF , (long )&termios); -sys_read (fd, &c,1 ); +kern_sys_ioctl (fd,TCSETSF , (long )&termios); +kern_sys_read (fd, &c,1 ); termios.c_lflag |=ICANON ; -sys_ioctl (fd,TCSETSF , (long )&termios); -sys_close (fd); +kern_sys_ioctl (fd,TCSETSF , (long )&termios); +kern_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 *)"." ); +kern_sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +kern_sys_chroot ("." ); }
init/do_mounts_initrd.c +25 -23
108 lines not on this page · raw message
init/do_mounts_md.c +15 -14
@@ -3,6 +3,7 @@#include <linux/raid/md_p.h> #include "do_mounts.h" +#include "sys-wrapper.h" /* * When md (and any require personalities) are compiled into the kernel
@@ -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 =kern_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 (kern_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); +kern_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 =kern_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 =kern_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); +kern_sys_ioctl (fd,ADD_NEW_DISK , (long )&dinfo); } }if (!err) - err =sys_ioctl (fd,RUN_ARRAY ,0 ); + err =kern_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 ); +kern_sys_close (fd); + fd =kern_sys_open (name,0 ,0 ); +kern_sys_ioctl (fd,BLKRRPART ,0 ); } -sys_close (fd); +kern_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 =kern_sys_open ("/dev/md0" ,0 ,0 );if (fd >=0 ) { -sys_ioctl (fd,RAID_AUTORUN , raid_autopart); -sys_close (fd); +kern_sys_ioctl (fd,RAID_AUTORUN , raid_autopart); +kern_sys_close (fd); } }
init/do_mounts_rd.c +19 -18
@@ -10,6 +10,7 @@#include <linux/slab.h> #include "do_mounts.h" +#include "sys-wrapper.h" #include "../fs/squashfs/squashfs_fs.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); +kern_sys_lseek (fd, start_block *BLOCK_SIZE ,0 ); +kern_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); +kern_sys_lseek (fd, (start_block+1 ) *BLOCK_SIZE ,0 ); +kern_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 ); +kern_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 =kern_sys_open ("/dev/ram" ,O_RDWR ,0 );if (out_fd <0 ) goto out; - in_fd =sys_open (from,O_RDONLY ,0 ); + in_fd =kern_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 (kern_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 (kern_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 (kern_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 =kern_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 ); +kern_sys_read (in_fd, buf,BLOCK_SIZE ); +kern_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); +kern_sys_close (in_fd); noclose_input: -sys_close (out_fd); +kern_sys_close (out_fd); out:kfree (buf); -sys_unlink ((const char __user __force *)"/dev/ram" ); +kern_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 =kern_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 =kern_sys_write (crd_outfd, window, outcnt);if (written != outcnt) {if (decompress_error ==0 ) printk(KERN_ERR
init/initramfs.c +31 -30
159 lines not on this page · raw message
init/main.c +5 -4
@@ -68,6 +68,7 @@#include <linux/sfi.h> #include <linux/shmem_fs.h> #include <linux/slab.h> +#include "sys-wrapper.h" #include <asm/io.h> #include <asm/bugs.h>
@@ -893,11 +894,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 (kern_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 )kern_sys_dup (0 ); + (void )kern_sys_dup (0 );/* * check if there is an early userspace init. If yes, let it do all * the work
@@ -906,7 +907,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 (kern_sys_access (ramdisk_execute_command,0 ) !=0 ) { ramdisk_execute_command =NULL ;prepare_namespace (); }
init/noinitramfs.c +5 -5
@@ -29,17 +29,17 @@ static int __init default_rootfs(void) {int err; - err =sys_mkdir ((const char __user __force *)"/dev" ,0755 ); + err =kern_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 =kern_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 =kern_sys_mkdir ("/root" ,0700 );if (err <0 ) goto out;
Signature · 1 line
1.7.2.2
Re: [PATCH v3 2/2] init: use kern_sys_* wrappers instead of syscall
Quoted 2 lines · Namhyung Kim
replace direct syscall invocations to its wrapper functions defined in
init/sys-wrapper.h
Please explain again that this fixes sparse warnings. And list the sparse warnings that gets fixed - or at least some abbrevated sample of tham.
Comment about inverse christmas tree apply to this patch in a few spots.
The patch does not apply to -linus.
In realise this is because it is made on top of another patch of yours that is already in -mm.
But it would be better to say that this first patch should be replaced by this second patch that does the same and more.
Sam