Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4404063ybz; Mon, 20 Apr 2020 23:16:30 -0700 (PDT) X-Google-Smtp-Source: APiQypJpfoEgLXJa6LvkRRX2aL3FbeU68KN3Qf09RzAmLJ9QHXOaC4fl7v33wVLax7ES2iCbx2T2 X-Received: by 2002:a17:906:b217:: with SMTP id p23mr18928641ejz.136.1587449790206; Mon, 20 Apr 2020 23:16:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587449790; cv=none; d=google.com; s=arc-20160816; b=YqwToZIL1sZOcYnhX7BaBs1TcIH5CXY62VC7rH+Ah5kkonPPWhFXyTixw7NS8cFE11 LNor4HdeZt8mGo3Ii+4h/rYALcbUrMgdqiRWpV1Oc14Zi312Xqg5Mv+HObLJQxJR5yG+ vXcBQn7vU77Y98HxzbZnBwy90k95JmqV6NLx2QqjWIm/hUAIa++O++7OPJRjQM7pUmCF y2Unnvzc/av+cHBX4NN3RaaBlPPabfifpqyvFqNBvh5xyW6NpoTg1MI26pfGe+vC7aaR NA/DefBMJzf+JLDZVIcSTuB1zzpq1x4n5fgluRVv7cqQrZh4vA/Aqm6VbmTJOi/fxovr eVlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RC9ybl3hA+urex0EYzCztECLSLKgmu4AWH6vGEA4kxk=; b=eAM7ToCUqUDHTSBkURg+Kb6Dgy4iv8hDrGQsOG5ImP5ik1ZD+VkAf68O9ARkDcAbNK u1dKcD8w9ieQxYVRLYiqfuLzu03gda+l0STnGFxYxLArUQ6BSUEwr/RQsZU8U89q+FsV LI4/38Vq4c2C0SHuaAzTC+ZP5mHbpnSHbV09TwMnnaOk+dn6VT6iJwwaREjSFA7NLXFl LNafIiWjlyThNE6xfl9S8Nocm8Oo39hTzdLnIAKbRcIMfeCj3BgeQrBWCU7Lb33wjlmI 5FQEW17qBkXAStjs2oBB/Viacb1hpNPb112UKWYzsglvY5bbhtV26wLnWamjn7D7SrPi heDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dJuSB5dY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u25si1039700edy.422.2020.04.20.23.16.07; Mon, 20 Apr 2020 23:16:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dJuSB5dY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbgDUGMe (ORCPT + 99 others); Tue, 21 Apr 2020 02:12:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725901AbgDUGMd (ORCPT ); Tue, 21 Apr 2020 02:12:33 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94712C061A0F; Mon, 20 Apr 2020 23:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=RC9ybl3hA+urex0EYzCztECLSLKgmu4AWH6vGEA4kxk=; b=dJuSB5dY+PXMXc6Yewu13AVtrN QmpAF4sCTlho+82mD2kbA2YsKACisjoIoOzgANQLdzSZzDQbZQE4Z5Jh2T9QkTGaa0IQA4NOQszCd EM9KY7W2zjcTSpi0C4DF1S4YOwF6mE+eJtsJ6cwd42xSUDVHZx2ZqzZNUZLcKS3PAp5UDbvOK+ZdD kcTIdcZm2vZuw+X+a60jCEg5VHrKEPY4NDDp05LF94YYBkbcm/1tXDUB1aaqCOg++pwe6XPkrG+pq aeCHfZlhRGcLvsPSSI4AHTwXDrbzy8JcrDk5DWNPQseAmqZJv350Qqv5PBC41z5J6qxP2jvsOO52S M47tMWyQ==; Received: from [2001:4bb8:191:e12c:292e:7dec:cf13:becd] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQm91-0000IA-2I; Tue, 21 Apr 2020 06:12:31 +0000 From: Christoph Hellwig To: Stefan Haberland , Jan Hoeppner , Jens Axboe , Heiko Carstens , Vasily Gorbik , Christian Borntraeger Cc: linux-s390@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] dasd: refactor dasd_ioctl_information Date: Tue, 21 Apr 2020 08:12:24 +0200 Message-Id: <20200421061226.33731-2-hch@lst.de> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200421061226.33731-1-hch@lst.de> References: <20200421061226.33731-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prepare for in-kernel callers of this functionality. Signed-off-by: Christoph Hellwig --- drivers/s390/block/dasd_ioctl.c | 38 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index 9a5f3add325f..dabcb4ce92da 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -457,10 +457,9 @@ static int dasd_ioctl_read_profile(struct dasd_block *block, void __user *argp) /* * Return dasd information. Used for BIODASDINFO and BIODASDINFO2. */ -static int dasd_ioctl_information(struct dasd_block *block, - unsigned int cmd, void __user *argp) +static int __dasd_ioctl_information(struct dasd_block *block, + struct dasd_information2_t *dasd_info) { - struct dasd_information2_t *dasd_info; struct subchannel_id sch_id; struct ccw_dev_id dev_id; struct dasd_device *base; @@ -473,10 +472,6 @@ static int dasd_ioctl_information(struct dasd_block *block, if (!base->discipline || !base->discipline->fill_info) return -EINVAL; - dasd_info = kzalloc(sizeof(struct dasd_information2_t), GFP_KERNEL); - if (dasd_info == NULL) - return -ENOMEM; - rc = base->discipline->fill_info(base, dasd_info); if (rc) { kfree(dasd_info); @@ -520,15 +515,24 @@ static int dasd_ioctl_information(struct dasd_block *block, list_for_each(l, &base->ccw_queue) dasd_info->chanq_len++; spin_unlock_irqrestore(&block->queue_lock, flags); + return 0; +} - rc = 0; - if (copy_to_user(argp, dasd_info, - ((cmd == (unsigned int) BIODASDINFO2) ? - sizeof(struct dasd_information2_t) : - sizeof(struct dasd_information_t)))) - rc = -EFAULT; +static int dasd_ioctl_information(struct dasd_block *block, void __user *argp, + size_t copy_size) +{ + struct dasd_information2_t *dasd_info; + int error = 0; + + dasd_info = kzalloc(sizeof(*dasd_info), GFP_KERNEL); + if (!dasd_info) + return -ENOMEM; + + error = __dasd_ioctl_information(block, dasd_info); + if (!error && copy_to_user(argp, dasd_info, copy_size)) + error = -EFAULT; kfree(dasd_info); - return rc; + return error; } /* @@ -622,10 +626,12 @@ int dasd_ioctl(struct block_device *bdev, fmode_t mode, rc = dasd_ioctl_check_format(bdev, argp); break; case BIODASDINFO: - rc = dasd_ioctl_information(block, cmd, argp); + rc = dasd_ioctl_information(block, argp, + sizeof(struct dasd_information_t)); break; case BIODASDINFO2: - rc = dasd_ioctl_information(block, cmd, argp); + rc = dasd_ioctl_information(block, argp, + sizeof(struct dasd_information2_t)); break; case BIODASDPRRD: rc = dasd_ioctl_read_profile(block, argp); -- 2.26.1