Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[S390] vmcp cleanup

A number of small changes to vmcp:
- Change preferred email address.
- Use PRINT_xxx machros from debug.h like most s390 drivers, define
"vmcp:" as PRINTK_HEADER and wrap error message at column 80.
- Add error number to error message.
- Update copyright, as I touched this file.
- Small whitespace diff.
- Use mutex instead of semaphore (Thanks Heiko for the patch)
- Don't register debug feature on failure.
- Check debug feature registration on init to avoid a potential oops
on unload if the debug feature could not be registered--> 2 more
messages.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Christian Borntraeger and committed by
Martin Schwidefsky
d9d119f1 6cbed91a

+53 -40
+51 -38
drivers/s390/char/vmcp.c
··· 1 1 /* 2 - * Copyright (C) 2004,2005 IBM Corporation 2 + * Copyright IBM Corp. 2004,2007 3 3 * Interface implementation for communication with the z/VM control program 4 - * Author(s): Christian Borntraeger <cborntra@de.ibm.com> 4 + * Author(s): Christian Borntraeger <borntraeger@de.ibm.com> 5 5 * 6 6 * 7 7 * z/VMs CP offers the possibility to issue commands via the diagnose code 8 ··· 22 22 #include "vmcp.h" 23 23 24 24 MODULE_LICENSE("GPL"); 25 - MODULE_AUTHOR("Christian Borntraeger <cborntra@de.ibm.com>"); 25 + MODULE_AUTHOR("Christian Borntraeger <borntraeger@de.ibm.com>"); 26 26 MODULE_DESCRIPTION("z/VM CP interface"); 27 + 28 + #define PRINTK_HEADER "vmcp: " 27 29 28 30 static debug_info_t *vmcp_debug; 29 31 ··· 42 40 session->bufsize = PAGE_SIZE; 43 41 session->response = NULL; 44 42 session->resp_size = 0; 45 - init_MUTEX(&session->mutex); 43 + mutex_init(&session->mutex); 46 44 file->private_data = session; 47 45 return nonseekable_open(inode, file); 48 46 } ··· 59 57 } 60 58 61 59 static ssize_t 62 - vmcp_read(struct file *file, char __user * buff, size_t count, loff_t * ppos) 60 + vmcp_read(struct file *file, char __user *buff, size_t count, loff_t *ppos) 63 61 { 64 62 size_t tocopy; 65 63 struct vmcp_session *session; 66 64 67 65 session = (struct vmcp_session *)file->private_data; 68 - if (down_interruptible(&session->mutex)) 66 + if (mutex_lock_interruptible(&session->mutex)) 69 67 return -ERESTARTSYS; 70 68 if (!session->response) { 71 - up(&session->mutex); 69 + mutex_unlock(&session->mutex); 72 70 return 0; 73 71 } 74 72 if (*ppos > session->resp_size) { 75 - up(&session->mutex); 73 + mutex_unlock(&session->mutex); 76 74 return 0; 77 75 } 78 76 tocopy = min(session->resp_size - (size_t) (*ppos), count); 79 - tocopy = min(tocopy,session->bufsize - (size_t) (*ppos)); 77 + tocopy = min(tocopy, session->bufsize - (size_t) (*ppos)); 80 78 81 79 if (copy_to_user(buff, session->response + (*ppos), tocopy)) { 82 - up(&session->mutex); 80 + mutex_unlock(&session->mutex); 83 81 return -EFAULT; 84 82 } 85 - up(&session->mutex); 83 + mutex_unlock(&session->mutex); 86 84 *ppos += tocopy; 87 85 return tocopy; 88 86 } 89 87 90 88 static ssize_t 91 - vmcp_write(struct file *file, const char __user * buff, size_t count, 92 - loff_t * ppos) 89 + vmcp_write(struct file *file, const char __user *buff, size_t count, 90 + loff_t *ppos) 93 91 { 94 92 char *cmd; 95 93 struct vmcp_session *session; ··· 105 103 } 106 104 cmd[count] = '\0'; 107 105 session = (struct vmcp_session *)file->private_data; 108 - if (down_interruptible(&session->mutex)) { 106 + if (mutex_lock_interruptible(&session->mutex)) { 109 107 kfree(cmd); 110 108 return -ERESTARTSYS; 111 109 } 112 110 if (!session->response) 113 111 session->response = (char *)__get_free_pages(GFP_KERNEL 114 - | __GFP_REPEAT | GFP_DMA, 112 + | __GFP_REPEAT | GFP_DMA, 115 113 get_order(session->bufsize)); 116 114 if (!session->response) { 117 - up(&session->mutex); 115 + mutex_unlock(&session->mutex); 118 116 kfree(cmd); 119 117 return -ENOMEM; 120 118 } 121 119 debug_text_event(vmcp_debug, 1, cmd); 122 - session->resp_size = cpcmd(cmd, session->response, 123 - session->bufsize, 124 - &session->resp_code); 125 - up(&session->mutex); 120 + session->resp_size = cpcmd(cmd, session->response, session->bufsize, 121 + &session->resp_code); 122 + mutex_unlock(&session->mutex); 126 123 kfree(cmd); 127 124 *ppos = 0; /* reset the file pointer after a command */ 128 125 return count; ··· 146 145 int temp; 147 146 148 147 session = (struct vmcp_session *)file->private_data; 149 - if (down_interruptible(&session->mutex)) 148 + if (mutex_lock_interruptible(&session->mutex)) 150 149 return -ERESTARTSYS; 151 150 switch (cmd) { 152 151 case VMCP_GETCODE: 153 152 temp = session->resp_code; 154 - up(&session->mutex); 153 + mutex_unlock(&session->mutex); 155 154 return put_user(temp, (int __user *)arg); 156 155 case VMCP_SETBUF: 157 156 free_pages((unsigned long)session->response, ··· 162 161 session->bufsize = PAGE_SIZE; 163 162 temp = -EINVAL; 164 163 } 165 - up(&session->mutex); 164 + mutex_unlock(&session->mutex); 166 165 return temp; 167 166 case VMCP_GETSIZE: 168 167 temp = session->resp_size; 169 - up(&session->mutex); 168 + mutex_unlock(&session->mutex); 170 169 return put_user(temp, (int __user *)arg); 171 170 default: 172 - up(&session->mutex); 171 + mutex_unlock(&session->mutex); 173 172 return -ENOIOCTLCMD; 174 173 } 175 174 } ··· 181 180 .read = vmcp_read, 182 181 .write = vmcp_write, 183 182 .unlocked_ioctl = vmcp_ioctl, 184 - .compat_ioctl = vmcp_ioctl 183 + .compat_ioctl = vmcp_ioctl, 185 184 }; 186 185 187 186 static struct miscdevice vmcp_dev = { ··· 195 194 int ret; 196 195 197 196 if (!MACHINE_IS_VM) { 198 - printk(KERN_WARNING 199 - "z/VM CP interface is only available under z/VM\n"); 197 + PRINT_WARN("z/VM CP interface is only available under z/VM\n"); 200 198 return -ENODEV; 201 199 } 202 - ret = misc_register(&vmcp_dev); 203 - if (!ret) 204 - printk(KERN_INFO "z/VM CP interface loaded\n"); 205 - else 206 - printk(KERN_WARNING 207 - "z/VM CP interface not loaded. Could not register misc device.\n"); 208 200 vmcp_debug = debug_register("vmcp", 1, 1, 240); 209 - debug_register_view(vmcp_debug, &debug_hex_ascii_view); 210 - return ret; 201 + if (!vmcp_debug) { 202 + PRINT_ERR("z/VM CP interface not loaded. Could not register " 203 + "debug feature\n"); 204 + return -ENOMEM; 205 + } 206 + ret = debug_register_view(vmcp_debug, &debug_hex_ascii_view); 207 + if (ret) { 208 + PRINT_ERR("z/VM CP interface not loaded. Could not register " 209 + "debug feature view. Error code: %d\n", ret); 210 + debug_unregister(vmcp_debug); 211 + return ret; 212 + } 213 + ret = misc_register(&vmcp_dev); 214 + if (ret) { 215 + PRINT_ERR("z/VM CP interface not loaded. Could not register " 216 + "misc device. Error code: %d\n", ret); 217 + debug_unregister(vmcp_debug); 218 + return ret; 219 + } 220 + PRINT_INFO("z/VM CP interface loaded\n"); 221 + return 0; 211 222 } 212 223 213 224 static void __exit vmcp_exit(void) 214 225 { 215 - WARN_ON(misc_deregister(&vmcp_dev) != 0); 226 + misc_deregister(&vmcp_dev); 216 227 debug_unregister(vmcp_debug); 217 - printk(KERN_INFO "z/VM CP interface unloaded.\n"); 228 + PRINT_INFO("z/VM CP interface unloaded.\n"); 218 229 } 219 230 220 231 module_init(vmcp_init);
+2 -2
drivers/s390/char/vmcp.h
··· 12 12 * The idea of this driver is based on cpint from Neale Ferguson 13 13 */ 14 14 15 - #include <asm/semaphore.h> 16 15 #include <linux/ioctl.h> 16 + #include <linux/mutex.h> 17 17 18 18 #define VMCP_GETCODE _IOR(0x10, 1, int) 19 19 #define VMCP_SETBUF _IOW(0x10, 2, int) ··· 26 26 int resp_code; 27 27 /* As we use copy_from/to_user, which might * 28 28 * sleep and cannot use a spinlock */ 29 - struct semaphore mutex; 29 + struct mutex mutex; 30 30 };