From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AB8JxZqsbcYPFVA9CueUeVeJYqpIxQi382LQXTWiFrr5/NCGofnJ7D/yyYnYNgTIF3Dpz98M9Qx1 ARC-Seal: i=1; a=rsa-sha256; t=1525284791; cv=none; d=google.com; s=arc-20160816; b=G27pROkF0Yvl21gLNx0pY2h7iQa2DtWoE289EtL8AGRaIxOOsJa5TAPZZ66CTJQfj7 9apKF8qPXcDtucI9lJG17eW10iUU8f2OxVbLYCmM2ngwc5ppdAwH7Nol9p9dMAkZoY8Q OK/seXU2Dj+nJc/3g/Hpyta8peLj2Ax3n9ICFWkRR6SCU6cDU1lU9tMcPIzb7MAWFmYL ePCuWhFwsDOf/02ap+wXsIFxcIUyFDulfkuLskH5XvQ1igec2FksIPKNyflxJe67A3+z rULEBZ0wvmOCoEsrwdagiDujwWxDQL8/W0i0nlVNk4iNoZ2k2QrSdQMaml036oNWJnRI Xltw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:dkim-signature:arc-authentication-results; bh=L3ces/RLRm4gAb4bh63e9nfFdnkV77OKNTGOpM32Inw=; b=ibgNBIafi5fmrzk6e8ZreKnrZQMvQbtf3KT7kQbuNR741hVJLMae82x7i/q+V2OI/9 VVJKnl/68BvzlgDa73m/f0AWvo5Lr8ko39uFqAfcgagKlbHjdk3PNSQ15LLo5nNJnLPm RxYMvDlsPeTmWWTHrzBgaaZXS8GzujuzJ5cDhPRDn9W8ztweieVm65rC7ZeKKL+ts0Y4 jkQ/GpuceocAB+9THvq/yrvKIrg+IdcK3O37Gp2HEGe3wMuaQboYS7EP5+4nHzIOn7vS RN8ZfPCHZ3f7/SjC7V343+4P53WOQNXbaRB5uRBb0xKFvVL1YDYcBDFJADge2Gtbzjk3 8Y7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=bNdFLlBF; spf=pass (google.com: best guess record for domain of jsimmons@infradead.org designates 2001:8b0:10b:1236::1 as permitted sender) smtp.mailfrom=jsimmons@infradead.org Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=bNdFLlBF; spf=pass (google.com: best guess record for domain of jsimmons@infradead.org designates 2001:8b0:10b:1236::1 as permitted sender) smtp.mailfrom=jsimmons@infradead.org Date: Wed, 2 May 2018 19:13:06 +0100 (BST) From: James Simmons To: NeilBrown cc: Oleg Drokin , Greg Kroah-Hartman , Andreas Dilger , Linux Kernel Mailing List , Lustre Development List Subject: Re: [PATCH 09/10] staging: lustre: move remaining code from linux-module.c to module.c In-Reply-To: <152514675915.17843.13015150157081908310.stgit@noble> Message-ID: References: <152514658325.17843.11455067361317157487.stgit@noble> <152514675915.17843.13015150157081908310.stgit@noble> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180502_191306_579894_DE5331A6 X-CRM114-Status: GOOD ( 31.25 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 NO_RELAYS Informational: message was not relayed via SMTP X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1599232383653036659?= X-GMAIL-MSGID: =?utf-8?q?1599377025180218780?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: > There is no longer any need to keep this code separate, > and now we can remove linux-module.c > > Signed-off-by: NeilBrown Reviewed-by: James Simmons > --- > .../staging/lustre/include/linux/libcfs/libcfs.h | 4 > drivers/staging/lustre/lnet/libcfs/Makefile | 1 > .../lustre/lnet/libcfs/linux/linux-module.c | 168 -------------------- > drivers/staging/lustre/lnet/libcfs/module.c | 131 ++++++++++++++++ > 4 files changed, 131 insertions(+), 173 deletions(-) > delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-module.c > > diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h > index 9263e151451b..d420449b620e 100644 > --- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h > +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h > @@ -138,10 +138,6 @@ struct libcfs_ioctl_handler { > int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand); > int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand); > > -int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, > - const struct libcfs_ioctl_hdr __user *uparam); > -int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data); > - > #define _LIBCFS_H > > /** > diff --git a/drivers/staging/lustre/lnet/libcfs/Makefile b/drivers/staging/lustre/lnet/libcfs/Makefile > index e6fda27fdabd..e73515789a11 100644 > --- a/drivers/staging/lustre/lnet/libcfs/Makefile > +++ b/drivers/staging/lustre/lnet/libcfs/Makefile > @@ -5,7 +5,6 @@ subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include > obj-$(CONFIG_LNET) += libcfs.o > > libcfs-linux-objs := linux-tracefile.o linux-debug.o > -libcfs-linux-objs += linux-module.o > libcfs-linux-objs += linux-crypto.o > libcfs-linux-objs += linux-crypto-adler.o > > diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c > deleted file mode 100644 > index 954b681f9db7..000000000000 > --- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c > +++ /dev/null > @@ -1,168 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0 > -/* > - * GPL HEADER START > - * > - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. > - * > - * This program is free software; you can redistribute it and/or modify > - * it under the terms of the GNU General Public License version 2 only, > - * 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 version 2 for more details (a copy is included > - * in the LICENSE file that accompanied this code). > - * > - * You should have received a copy of the GNU General Public License > - * version 2 along with this program; If not, see > - * http://www.gnu.org/licenses/gpl-2.0.html > - * > - * GPL HEADER END > - */ > -/* > - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. > - * Use is subject to license terms. > - * > - * Copyright (c) 2012, Intel Corporation. > - */ > -/* > - * This file is part of Lustre, http://www.lustre.org/ > - * Lustre is a trademark of Sun Microsystems, Inc. > - */ > - > -#define DEBUG_SUBSYSTEM S_LNET > - > -#include > -#include > - > -static inline size_t libcfs_ioctl_packlen(struct libcfs_ioctl_data *data) > -{ > - size_t len = sizeof(*data); > - > - len += cfs_size_round(data->ioc_inllen1); > - len += cfs_size_round(data->ioc_inllen2); > - return len; > -} > - > -static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) > -{ > - if (data->ioc_hdr.ioc_len > BIT(30)) { > - CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n"); > - return true; > - } > - if (data->ioc_inllen1 > BIT(30)) { > - CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n"); > - return true; > - } > - if (data->ioc_inllen2 > BIT(30)) { > - CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n"); > - return true; > - } > - if (data->ioc_inlbuf1 && !data->ioc_inllen1) { > - CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n"); > - return true; > - } > - if (data->ioc_inlbuf2 && !data->ioc_inllen2) { > - CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n"); > - return true; > - } > - if (data->ioc_pbuf1 && !data->ioc_plen1) { > - CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n"); > - return true; > - } > - if (data->ioc_pbuf2 && !data->ioc_plen2) { > - CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n"); > - return true; > - } > - if (data->ioc_plen1 && !data->ioc_pbuf1) { > - CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n"); > - return true; > - } > - if (data->ioc_plen2 && !data->ioc_pbuf2) { > - CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n"); > - return true; > - } > - if ((u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) { > - CERROR("LIBCFS ioctl: packlen != ioc_len\n"); > - return true; > - } > - if (data->ioc_inllen1 && > - data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { > - CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n"); > - return true; > - } > - if (data->ioc_inllen2 && > - data->ioc_bulk[cfs_size_round(data->ioc_inllen1) + > - data->ioc_inllen2 - 1] != '\0') { > - CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n"); > - return true; > - } > - return false; > -} > - > -int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data) > -{ > - if (libcfs_ioctl_is_invalid(data)) { > - CERROR("libcfs ioctl: parameter not correctly formatted\n"); > - return -EINVAL; > - } > - > - if (data->ioc_inllen1) > - data->ioc_inlbuf1 = &data->ioc_bulk[0]; > - > - if (data->ioc_inllen2) > - data->ioc_inlbuf2 = &data->ioc_bulk[0] + > - cfs_size_round(data->ioc_inllen1); > - > - return 0; > -} > - > -int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, > - const struct libcfs_ioctl_hdr __user *uhdr) > -{ > - struct libcfs_ioctl_hdr hdr; > - int err; > - > - if (copy_from_user(&hdr, uhdr, sizeof(hdr))) > - return -EFAULT; > - > - if (hdr.ioc_version != LIBCFS_IOCTL_VERSION && > - hdr.ioc_version != LIBCFS_IOCTL_VERSION2) { > - CERROR("libcfs ioctl: version mismatch expected %#x, got %#x\n", > - LIBCFS_IOCTL_VERSION, hdr.ioc_version); > - return -EINVAL; > - } > - > - if (hdr.ioc_len < sizeof(hdr)) { > - CERROR("libcfs ioctl: user buffer too small for ioctl\n"); > - return -EINVAL; > - } > - > - if (hdr.ioc_len > LIBCFS_IOC_DATA_MAX) { > - CERROR("libcfs ioctl: user buffer is too large %d/%d\n", > - hdr.ioc_len, LIBCFS_IOC_DATA_MAX); > - return -EINVAL; > - } > - > - *hdr_pp = kvmalloc(hdr.ioc_len, GFP_KERNEL); > - if (!*hdr_pp) > - return -ENOMEM; > - > - if (copy_from_user(*hdr_pp, uhdr, hdr.ioc_len)) { > - err = -EFAULT; > - goto free; > - } > - > - if ((*hdr_pp)->ioc_version != hdr.ioc_version || > - (*hdr_pp)->ioc_len != hdr.ioc_len) { > - err = -EINVAL; > - goto free; > - } > - > - return 0; > - > -free: > - kvfree(*hdr_pp); > - return err; > -} > diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c > index 3fb150a57f49..4c4bf09a78dd 100644 > --- a/drivers/staging/lustre/lnet/libcfs/module.c > +++ b/drivers/staging/lustre/lnet/libcfs/module.c > @@ -95,6 +95,137 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand) > } > EXPORT_SYMBOL(libcfs_deregister_ioctl); > > +static inline size_t libcfs_ioctl_packlen(struct libcfs_ioctl_data *data) > +{ > + size_t len = sizeof(*data); > + > + len += cfs_size_round(data->ioc_inllen1); > + len += cfs_size_round(data->ioc_inllen2); > + return len; > +} > + > +static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) > +{ > + if (data->ioc_hdr.ioc_len > BIT(30)) { > + CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n"); > + return true; > + } > + if (data->ioc_inllen1 > BIT(30)) { > + CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n"); > + return true; > + } > + if (data->ioc_inllen2 > BIT(30)) { > + CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n"); > + return true; > + } > + if (data->ioc_inlbuf1 && !data->ioc_inllen1) { > + CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n"); > + return true; > + } > + if (data->ioc_inlbuf2 && !data->ioc_inllen2) { > + CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n"); > + return true; > + } > + if (data->ioc_pbuf1 && !data->ioc_plen1) { > + CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n"); > + return true; > + } > + if (data->ioc_pbuf2 && !data->ioc_plen2) { > + CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n"); > + return true; > + } > + if (data->ioc_plen1 && !data->ioc_pbuf1) { > + CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n"); > + return true; > + } > + if (data->ioc_plen2 && !data->ioc_pbuf2) { > + CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n"); > + return true; > + } > + if ((u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) { > + CERROR("LIBCFS ioctl: packlen != ioc_len\n"); > + return true; > + } > + if (data->ioc_inllen1 && > + data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { > + CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n"); > + return true; > + } > + if (data->ioc_inllen2 && > + data->ioc_bulk[cfs_size_round(data->ioc_inllen1) + > + data->ioc_inllen2 - 1] != '\0') { > + CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n"); > + return true; > + } > + return false; > +} > + > +static int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data) > +{ > + if (libcfs_ioctl_is_invalid(data)) { > + CERROR("libcfs ioctl: parameter not correctly formatted\n"); > + return -EINVAL; > + } > + > + if (data->ioc_inllen1) > + data->ioc_inlbuf1 = &data->ioc_bulk[0]; > + > + if (data->ioc_inllen2) > + data->ioc_inlbuf2 = &data->ioc_bulk[0] + > + cfs_size_round(data->ioc_inllen1); > + > + return 0; > +} > + > +static int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, > + const struct libcfs_ioctl_hdr __user *uhdr) > +{ > + struct libcfs_ioctl_hdr hdr; > + int err; > + > + if (copy_from_user(&hdr, uhdr, sizeof(hdr))) > + return -EFAULT; > + > + if (hdr.ioc_version != LIBCFS_IOCTL_VERSION && > + hdr.ioc_version != LIBCFS_IOCTL_VERSION2) { > + CERROR("libcfs ioctl: version mismatch expected %#x, got %#x\n", > + LIBCFS_IOCTL_VERSION, hdr.ioc_version); > + return -EINVAL; > + } > + > + if (hdr.ioc_len < sizeof(hdr)) { > + CERROR("libcfs ioctl: user buffer too small for ioctl\n"); > + return -EINVAL; > + } > + > + if (hdr.ioc_len > LIBCFS_IOC_DATA_MAX) { > + CERROR("libcfs ioctl: user buffer is too large %d/%d\n", > + hdr.ioc_len, LIBCFS_IOC_DATA_MAX); > + return -EINVAL; > + } > + > + *hdr_pp = kvmalloc(hdr.ioc_len, GFP_KERNEL); > + if (!*hdr_pp) > + return -ENOMEM; > + > + if (copy_from_user(*hdr_pp, uhdr, hdr.ioc_len)) { > + err = -EFAULT; > + goto free; > + } > + > + if ((*hdr_pp)->ioc_version != hdr.ioc_version || > + (*hdr_pp)->ioc_len != hdr.ioc_len) { > + err = -EINVAL; > + goto free; > + } > + > + return 0; > + > +free: > + kvfree(*hdr_pp); > + return err; > +} > + > static int libcfs_ioctl(unsigned long cmd, void __user *uparam) > { > struct libcfs_ioctl_data *data = NULL; > > >