Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6281070imu; Mon, 21 Jan 2019 06:19:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN40tL4xb14BqOMhfDdZsSZT6zfx9UXQZvgHbv9l3xGgLs5sz7By7kEIIyxisrdjecIEdlS/ X-Received: by 2002:a17:902:3383:: with SMTP id b3mr29649534plc.170.1548080347505; Mon, 21 Jan 2019 06:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548080347; cv=none; d=google.com; s=arc-20160816; b=yM3jgccOWU8qS7oOlQnBb6lw0zriFRhaMR6+FqfOi7wjXDjuanNcIRq0+R7VwI+7J0 QTQf1B8TQ9jaXRHlXa6SuUn4h6FkJZtj61qdT8aD7ZC7B1XGO1eWiClavPEet9QUdBNx vfV5EE0eg+F6wt6cgik1RD5pyolHDLPiMZ+tejl6sdps6Eve/ECWJY7Khu0DFtG/DKEC rEIOY1VjQeyn+e1EyUffKybsGHv1/XkcU4u9YJWeodS7iB6yLBe3U3qlv2WcKzPcdYT8 D8dgHCnsGGjBXJg96FP37eD1ciYf6fVxG4GUSXLZHYjbUb4aLsi0bNkB5J7Taq0d78sr xKIQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Bzzk8IKubPNMcIJM7TnBK8v8XBFB/B+7clyR8m9epSc=; b=XiZR1xy10RnhXstJf6GdG13Jvwy/utgOxm9fHNnSOnCgoiceZwih73C8FMyC4ScrRC mKgOlqPfN8sUr2Q5TmnX4RsPcTySjr0kSQfcNGiaqWVM/XLnwFy1Z+W9lHzdgFNOsn8w 40UyMzRXtz/c/fHQ0khsW3HyYyozloicIhcNZI9nXH1jCIU3MuclaFcOlGVtSM1wrLl0 VGDeKqcw3gtvAhoHv0S3qVARQtlFsXKyQ/ox2e4h26p1gyWcKsSDePrxIVE8fsJ8eg9h iL3kv/i2RviBbtfCSVBOZf6SUzox83iedWILY6oHHDGY8iQi1ZP9De2sD+A2TpBXQugg uGmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="y4lS/dti"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u22si8403815pgk.335.2019.01.21.06.18.52; Mon, 21 Jan 2019 06:19:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="y4lS/dti"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730583AbfAUNuh (ORCPT + 99 others); Mon, 21 Jan 2019 08:50:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:33188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730569AbfAUNuc (ORCPT ); Mon, 21 Jan 2019 08:50:32 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C8D242063F; Mon, 21 Jan 2019 13:50:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548078631; bh=TfWSGYdOuYOQI/uzFHcj3Pjx0VkE1tpwlgaProSCWP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y4lS/dtil6Ueyx/3tbEYDo76CTKQN9FxMWun4JKN5lbbID7fRjPveu3yl3LRvCkUm Sf/yby1eFXuwPUCQ7VRZAU1KvkTvg3vG1Um7FlD+liATFTcS+F/YIwEpLBrxrmxRvc Y1DmUOKOxIsTJAtKO5eBlRRQxxyiw/w1ZlDNnlRA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Jens Axboe Subject: [PATCH 4.20 100/111] loop: Push loop_ctl_mutex down to loop_get_status() Date: Mon, 21 Jan 2019 14:43:34 +0100 Message-Id: <20190121122506.652884846@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121122455.819406896@linuxfoundation.org> References: <20190121122455.819406896@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit 4a5ce9ba5877e4640200d84a735361306ad1a1b8 upstream. Push loop_ctl_mutex down to loop_get_status() to avoid the unusual convention that the function gets called with loop_ctl_mutex held and releases it. Signed-off-by: Jan Kara Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1232,6 +1232,9 @@ loop_get_status(struct loop_device *lo, struct kstat stat; int ret; + ret = mutex_lock_killable_nested(&loop_ctl_mutex, 1); + if (ret) + return ret; if (lo->lo_state != Lo_bound) { mutex_unlock(&loop_ctl_mutex); return -ENXIO; @@ -1346,10 +1349,8 @@ loop_get_status_old(struct loop_device * struct loop_info64 info64; int err; - if (!arg) { - mutex_unlock(&loop_ctl_mutex); + if (!arg) return -EINVAL; - } err = loop_get_status(lo, &info64); if (!err) err = loop_info64_to_old(&info64, &info); @@ -1364,10 +1365,8 @@ loop_get_status64(struct loop_device *lo struct loop_info64 info64; int err; - if (!arg) { - mutex_unlock(&loop_ctl_mutex); + if (!arg) return -EINVAL; - } err = loop_get_status(lo, &info64); if (!err && copy_to_user(arg, &info64, sizeof(info64))) err = -EFAULT; @@ -1477,12 +1476,7 @@ static int lo_ioctl(struct block_device } break; case LOOP_GET_STATUS: - err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); - if (err) - return err; - err = loop_get_status_old(lo, (struct loop_info __user *) arg); - /* loop_get_status() unlocks loop_ctl_mutex */ - break; + return loop_get_status_old(lo, (struct loop_info __user *) arg); case LOOP_SET_STATUS64: err = -EPERM; if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) { @@ -1495,12 +1489,7 @@ static int lo_ioctl(struct block_device } break; case LOOP_GET_STATUS64: - err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); - if (err) - return err; - err = loop_get_status64(lo, (struct loop_info64 __user *) arg); - /* loop_get_status() unlocks loop_ctl_mutex */ - break; + return loop_get_status64(lo, (struct loop_info64 __user *) arg); case LOOP_SET_CAPACITY: case LOOP_SET_DIRECT_IO: case LOOP_SET_BLOCK_SIZE: @@ -1625,10 +1614,8 @@ loop_get_status_compat(struct loop_devic struct loop_info64 info64; int err; - if (!arg) { - mutex_unlock(&loop_ctl_mutex); + if (!arg) return -EINVAL; - } err = loop_get_status(lo, &info64); if (!err) err = loop_info64_to_compat(&info64, arg); @@ -1651,12 +1638,8 @@ static int lo_compat_ioctl(struct block_ } break; case LOOP_GET_STATUS: - err = mutex_lock_killable(&loop_ctl_mutex); - if (!err) { - err = loop_get_status_compat(lo, - (struct compat_loop_info __user *)arg); - /* loop_get_status() unlocks loop_ctl_mutex */ - } + err = loop_get_status_compat(lo, + (struct compat_loop_info __user *)arg); break; case LOOP_SET_CAPACITY: case LOOP_CLR_FD: