Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2935621pxk; Mon, 21 Sep 2020 00:23:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSlIkn68ogNLzQ5On/ENhsvYj0RMYzevakA9N4vhH3mYy+Mcr6renYz9ZO81/Ohzy5WrUv X-Received: by 2002:a17:906:fb04:: with SMTP id lz4mr5950031ejb.535.1600673012433; Mon, 21 Sep 2020 00:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600673012; cv=none; d=google.com; s=arc-20160816; b=JIUmLjgtSOBw80c0zDtsLuAwupl7R0CfPZdvIUMZtDAN1KOMSTx1MbtFzRIc2zwunZ GiP+Y0Kq1CnL6nBwNGAfYri7t4Xaiz+SCvhLCy/XhnNqKwj+XX7Bd/1L2WCr34SEAt/G 0Y4xoEWjeQSwADEglgdIOi5mxOMqIs4DkcUHtygCEU7/IRbg3RrFrnTLew6ij9ro2nDK dRFLJbytbkezHfeEfK/YBiF71CBXSpqZ7AZy33BzoWfz/WlFxLU8M98tl3x1jCFzOtjK s56ZTcJpXSxVMu10Ki8wDj9gsciFJAYLtP49sSiaMHPe8/qz89ZdUAAf3mxqI64I6c7r Rqyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OOOyqbfGBfADtTd2OFjO0d+j7/uUOQY5tAGUzrpX3bI=; b=hPbBxsfHIL1Qdh5ccAEYyHmb9Nvxv9ePzKUANxIh0ajX1OwdXl8MTWnZyD6QJi9NMr jzncQi1A821jlnyUHHe5jqUvkweG7nkK3MPsz5i/fAuzDU1VxYy+kadawzG9YNTT2AS0 2uR7mzdPOiK0w0armt9WqJNzsFq9NjEDCveDvSmXueqahJQ4gfonwltbyVd4do5mS6GK 9k3uvkPFkDRlpiMcIi64nqTClrc9R7xDI1wt1l3myFZsB15BpCPGc9rrcAnq7LwBXmGP U6cbpV+6zzx6QYPtlZuyTlgOCFOZ3EOYv0veLwaqV8YqmhLGExiX/ktOCPjHyMNHz0RS VNnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Fg+jVrRt; 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 dv18si7656156ejb.135.2020.09.21.00.23.09; Mon, 21 Sep 2020 00:23:32 -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=pass header.i=@infradead.org header.s=casper.20170209 header.b=Fg+jVrRt; 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 S1726710AbgIUHVN (ORCPT + 99 others); Mon, 21 Sep 2020 03:21:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726487AbgIUHUH (ORCPT ); Mon, 21 Sep 2020 03:20:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 685B6C0613CF; Mon, 21 Sep 2020 00:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=OOOyqbfGBfADtTd2OFjO0d+j7/uUOQY5tAGUzrpX3bI=; b=Fg+jVrRtZJpJ9kcTFRFiN5ur4w iNJb151F26Kg+6mk83/7FBN8HtwBsGu2VW2x2tPwIHqUbnWCynZVWMVEZRXUenkS2HO0I+io/+M9q yL+kBkDog+m/NbE8VIBZEdb1RLomNqZ0sf2ffr926uhdZysv+43dZQakXwVtLd5dpw9u288aY/26n OWcPmOPtiKB0fkN4Zn2kyiS0u3UDsuciOilbRoXujf99uG4brqxixaoeLyc03rZIKJY+BWJzqA3ww l3CP0o/N5Y02VaCZ1q7lmf7Khe3ZLNoluwHOKwyOmmkARD1A7i8lz5bhnuJlJb4YiFTxyH6iDKPSt yE89IMiQ==; Received: from p4fdb0c34.dip0.t-ipconnect.de ([79.219.12.52] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKG7B-0003F5-Dd; Mon, 21 Sep 2020 07:19:57 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Josef Bacik , Minchan Kim , Stefan Haberland , Jan Hoeppner , Joseph Qi , "Rafael J. Wysocki" , Pavel Machek , Len Brown , Andrew Morton , linux-kernel@vger.kernel.org, nbd@other.debian.org, linux-ide@vger.kernel.org, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com, linux-pm@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org Subject: [PATCH 07/14] raw: don't keep unopened block device around Date: Mon, 21 Sep 2020 09:19:51 +0200 Message-Id: <20200921071958.307589-8-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921071958.307589-1-hch@lst.de> References: <20200921071958.307589-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Turn binding into a normal dev_t as the struct block device doesn't buy us anything and use blkdev_open_by_dev to actually open it. Signed-off-by: Christoph Hellwig --- drivers/char/raw.c | 51 +++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/drivers/char/raw.c b/drivers/char/raw.c index ccf5bd528642da..5d52a1f4738c76 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c @@ -28,7 +28,8 @@ #include struct raw_device_data { - struct block_device *binding; + dev_t binding; + struct block_device *bdev; int inuse; }; @@ -73,14 +74,15 @@ static int raw_open(struct inode *inode, struct file *filp) /* * All we need to do on open is check that the device is bound. */ - bdev = raw_devices[minor].binding; err = -ENODEV; - if (!bdev) + if (!raw_devices[minor].binding) goto out; - bdgrab(bdev); - err = blkdev_get(bdev, filp->f_mode | FMODE_EXCL, raw_open); - if (err) + bdev = blkdev_get_by_dev(raw_devices[minor].binding, + filp->f_mode | FMODE_EXCL, raw_open); + if (IS_ERR(bdev)) { + err = PTR_ERR(bdev); goto out; + } err = set_blocksize(bdev, bdev_logical_block_size(bdev)); if (err) goto out1; @@ -90,6 +92,7 @@ static int raw_open(struct inode *inode, struct file *filp) file_inode(filp)->i_mapping = bdev->bd_inode->i_mapping; filp->private_data = bdev; + raw_devices[minor].bdev = bdev; mutex_unlock(&raw_mutex); return 0; @@ -110,7 +113,7 @@ static int raw_release(struct inode *inode, struct file *filp) struct block_device *bdev; mutex_lock(&raw_mutex); - bdev = raw_devices[minor].binding; + bdev = raw_devices[minor].bdev; if (--raw_devices[minor].inuse == 0) /* Here inode->i_mapping == bdev->bd_inode->i_mapping */ inode->i_mapping = &inode->i_data; @@ -133,6 +136,7 @@ raw_ioctl(struct file *filp, unsigned int command, unsigned long arg) static int bind_set(int number, u64 major, u64 minor) { dev_t dev = MKDEV(major, minor); + dev_t raw = MKDEV(RAW_MAJOR, number); struct raw_device_data *rawdev; int err = 0; @@ -166,25 +170,17 @@ static int bind_set(int number, u64 major, u64 minor) mutex_unlock(&raw_mutex); return -EBUSY; } - if (rawdev->binding) { - bdput(rawdev->binding); + if (rawdev->binding) module_put(THIS_MODULE); - } + + rawdev->binding = dev; if (!dev) { /* unbind */ - rawdev->binding = NULL; - device_destroy(raw_class, MKDEV(RAW_MAJOR, number)); + device_destroy(raw_class, raw); } else { - rawdev->binding = bdget(dev); - if (rawdev->binding == NULL) { - err = -ENOMEM; - } else { - dev_t raw = MKDEV(RAW_MAJOR, number); - __module_get(THIS_MODULE); - device_destroy(raw_class, raw); - device_create(raw_class, NULL, raw, NULL, - "raw%d", number); - } + __module_get(THIS_MODULE); + device_destroy(raw_class, raw); + device_create(raw_class, NULL, raw, NULL, "raw%d", number); } mutex_unlock(&raw_mutex); return err; @@ -192,18 +188,9 @@ static int bind_set(int number, u64 major, u64 minor) static int bind_get(int number, dev_t *dev) { - struct raw_device_data *rawdev; - struct block_device *bdev; - if (number <= 0 || number >= max_raw_minors) return -EINVAL; - - rawdev = &raw_devices[number]; - - mutex_lock(&raw_mutex); - bdev = rawdev->binding; - *dev = bdev ? bdev->bd_dev : 0; - mutex_unlock(&raw_mutex); + *dev = raw_devices[number].binding; return 0; } -- 2.28.0