From patchwork Thu Feb 7 00:03:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10800325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 96D85746 for ; Thu, 7 Feb 2019 00:07:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 839082D348 for ; Thu, 7 Feb 2019 00:07:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 781912D62D; Thu, 7 Feb 2019 00:07:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E376F2D348 for ; Thu, 7 Feb 2019 00:07:16 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 4639E4C3D2A; Wed, 6 Feb 2019 16:07:16 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 581024C3CEB for ; Wed, 6 Feb 2019 16:07:14 -0800 (PST) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 97A98ADE5; Thu, 7 Feb 2019 00:07:13 +0000 (UTC) From: NeilBrown To: Andreas Dilger , James Simmons , Oleg Drokin Date: Thu, 07 Feb 2019 11:03:33 +1100 Message-ID: <154949781327.10620.2294752316778817915.stgit@noble.brown> In-Reply-To: <154949776249.10620.1215070753973826063.stgit@noble.brown> References: <154949776249.10620.1215070753973826063.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 15/21] lustre: obdclass: char obd_ioctl_getdata type. X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of having obd_ioctl_getdata() return the allocated data as a "char *", return it as it really is, struct obd_ioctl_data * This avoids the need for extra variables and casts. Signed-off-by: NeilBrown --- drivers/staging/lustre/lustre/include/obd_class.h | 3 ++- drivers/staging/lustre/lustre/llite/dir.c | 17 +++++------------ drivers/staging/lustre/lustre/llite/llite_lib.c | 8 +++----- drivers/staging/lustre/lustre/lov/lov_obd.c | 15 ++++++--------- drivers/staging/lustre/lustre/obdclass/class_obd.c | 18 ++++++++---------- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h index 30b3e2c69f83..32d4ab6e78a0 100644 --- a/drivers/staging/lustre/lustre/include/obd_class.h +++ b/drivers/staging/lustre/lustre/include/obd_class.h @@ -1697,6 +1697,7 @@ struct root_squash_info { }; /* linux-module.c */ -int obd_ioctl_getdata(char **buf, int *len, void __user *arg); +struct obd_ioctl_data; +int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg); #endif /* __LINUX_OBD_CLASS_H */ diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c index fd1af4a5cdad..0c49244eaee8 100644 --- a/drivers/staging/lustre/lustre/llite/dir.c +++ b/drivers/staging/lustre/lustre/llite/dir.c @@ -1130,13 +1130,11 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } case IOC_MDC_LOOKUP: { int namelen, len = 0; - char *buf = NULL; char *filename; - rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg); + rc = obd_ioctl_getdata(&data, &len, (void __user *)arg); if (rc) return rc; - data = (void *)buf; filename = data->ioc_inlbuf1; namelen = strlen(filename); @@ -1155,12 +1153,11 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) goto out_free; } out_free: - kvfree(buf); + kvfree(data); return rc; } case LL_IOC_LMV_SETSTRIPE: { struct lmv_user_md *lum; - char *buf = NULL; char *filename; int namelen = 0; int lumlen = 0; @@ -1168,11 +1165,10 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) int len; int rc; - rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg); + rc = obd_ioctl_getdata(&data, &len, (void __user *)arg); if (rc) return rc; - data = (void *)buf; if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 || data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0) { rc = -EINVAL; @@ -1205,7 +1201,7 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) #endif rc = ll_dir_setdirstripe(dentry, lum, filename, mode); lmv_out_free: - kvfree(buf); + kvfree(data); return rc; } case LL_IOC_LMV_SET_DEFAULT_STRIPE: { @@ -1651,18 +1647,16 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return rc; } case LL_IOC_MIGRATE: { - char *buf = NULL; const char *filename; int namelen = 0; int len; int rc; int mdtidx; - rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg); + rc = obd_ioctl_getdata(&data, &len, (void __user *)arg); if (rc < 0) return rc; - data = (struct obd_ioctl_data *)buf; if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 || !data->ioc_inllen1 || !data->ioc_inllen2) { rc = -EINVAL; @@ -1684,7 +1678,6 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1); migrate_free: - kvfree(buf); return rc; } diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c index 8e09fdd7a96e..e2417cd5aaed 100644 --- a/drivers/staging/lustre/lustre/llite/llite_lib.c +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c @@ -2295,7 +2295,6 @@ int ll_obd_statfs(struct inode *inode, void __user *arg) { struct ll_sb_info *sbi = NULL; struct obd_export *exp; - char *buf = NULL; struct obd_ioctl_data *data = NULL; u32 type; int len = 0, rc; @@ -2311,11 +2310,10 @@ int ll_obd_statfs(struct inode *inode, void __user *arg) goto out_statfs; } - rc = obd_ioctl_getdata(&buf, &len, arg); + rc = obd_ioctl_getdata(&data, &len, arg); if (rc) goto out_statfs; - data = (void *)buf; if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 || !data->ioc_pbuf1 || !data->ioc_pbuf2) { rc = -EINVAL; @@ -2340,11 +2338,11 @@ int ll_obd_statfs(struct inode *inode, void __user *arg) goto out_statfs; } - rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL); + rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL); if (rc) goto out_statfs; out_statfs: - kvfree(buf); + kvfree(data); return rc; } diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c index 04d0a9ed1d05..fd769c39b482 100644 --- a/drivers/staging/lustre/lustre/lov/lov_obd.c +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c @@ -1039,27 +1039,24 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len, case OBD_IOC_LOV_GET_CONFIG: { struct obd_ioctl_data *data; struct lov_desc *desc; - char *buf = NULL; u32 *genp; len = 0; - if (obd_ioctl_getdata(&buf, &len, uarg)) + if (obd_ioctl_getdata(&data, &len, uarg)) return -EINVAL; - data = (struct obd_ioctl_data *)buf; - if (sizeof(*desc) > data->ioc_inllen1) { - kvfree(buf); + kvfree(data); return -EINVAL; } if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) { - kvfree(buf); + kvfree(data); return -EINVAL; } if (sizeof(u32) * count > data->ioc_inllen3) { - kvfree(buf); + kvfree(data); return -EINVAL; } @@ -1076,9 +1073,9 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len, *genp = lov->lov_tgts[i]->ltd_gen; } - if (copy_to_user(uarg, buf, len)) + if (copy_to_user(uarg, data, len)) rc = -EFAULT; - kvfree(buf); + kvfree(data); break; } case OBD_IOC_QUOTACTL: { diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c index b859ab19b9f6..2ef4fd41cdd0 100644 --- a/drivers/staging/lustre/lustre/obdclass/class_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c @@ -230,7 +230,7 @@ static int obd_ioctl_is_invalid(struct obd_ioctl_data *data) } /* buffer MUST be at least the size of obd_ioctl_hdr */ -int obd_ioctl_getdata(char **buf, int *len, void __user *arg) +int obd_ioctl_getdata(struct obd_ioctl_data **datap, int *len, void __user *arg) { struct obd_ioctl_data *data; struct obd_ioctl_hdr hdr; @@ -262,16 +262,16 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg) * obdfilter-survey is an example, which relies on ioctl. So we'd * better avoid vmalloc on ioctl path. LU-66 */ - *buf = kvzalloc(hdr.ioc_len, GFP_KERNEL); - if (!*buf) { + data = kvzalloc(hdr.ioc_len, GFP_KERNEL); + if (!data) { CERROR("Cannot allocate control buffer of len %d\n", hdr.ioc_len); return -EINVAL; } *len = hdr.ioc_len; - data = (struct obd_ioctl_data *)*buf; + *datap = data; - if (copy_from_user(*buf, arg, hdr.ioc_len)) { + if (copy_from_user(data, arg, hdr.ioc_len)) { err = -EFAULT; goto free_buf; } @@ -308,14 +308,13 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg) return 0; free_buf: - kvfree(*buf); + kvfree(data); return err; } EXPORT_SYMBOL(obd_ioctl_getdata); int class_handle_ioctl(unsigned int cmd, unsigned long arg) { - char *buf = NULL; struct obd_ioctl_data *data; struct libcfs_debug_ioctl_data *debug_data; struct obd_device *obd = NULL; @@ -330,11 +329,10 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) } CDEBUG(D_IOCTL, "cmd = %x\n", cmd); - if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) { + if (obd_ioctl_getdata(&data, &len, (void __user *)arg)) { CERROR("OBD ioctl: data error\n"); return -EINVAL; } - data = (struct obd_ioctl_data *)buf; switch (cmd) { case OBD_IOC_PROCESS_CFG: { @@ -545,7 +543,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) } out: - kvfree(buf); + kvfree(data); return err; } /* class_handle_ioctl */