From patchwork Tue Feb 19 00:09:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10819033 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 14AC36C2 for ; Tue, 19 Feb 2019 00:11:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F10EA2BDE4 for ; Tue, 19 Feb 2019 00:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E27462BDEC; Tue, 19 Feb 2019 00:11:41 +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 57F352BDE4 for ; Tue, 19 Feb 2019 00:11:40 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 0331E21FA54; Mon, 18 Feb 2019 16:11:40 -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 2B13121FA08 for ; Mon, 18 Feb 2019 16:11:38 -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 5C7AAB008; Tue, 19 Feb 2019 00:11:37 +0000 (UTC) From: NeilBrown To: James Simmons , Andreas Dilger , Oleg Drokin Date: Tue, 19 Feb 2019 11:09:04 +1100 Message-ID: <155053494481.24125.17153359714439231322.stgit@noble.brown> In-Reply-To: <155053473693.24125.6976971762921761309.stgit@noble.brown> References: <155053473693.24125.6976971762921761309.stgit@noble.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [lustre-devel] [PATCH 01/37] 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 Reviewed-by: James Simmons --- drivers/staging/lustre/lustre/include/obd_class.h | 3 ++- drivers/staging/lustre/lustre/llite/dir.c | 18 ++++++------------ 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, 25 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..17bb6185ba87 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,7 @@ 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); + kvfree(data); 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 2ee6b96f4830..b8fc74044fe3 100644 --- a/drivers/staging/lustre/lustre/obdclass/class_obd.c +++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c @@ -229,7 +229,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; @@ -261,16 +261,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; } @@ -307,14 +307,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; @@ -329,11 +328,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: { @@ -542,7 +540,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg) } out: - kvfree(buf); + kvfree(data); return err; } /* class_handle_ioctl */