From patchwork Tue Feb 6 02:25:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Srivatsa S. Bhat" X-Patchwork-Id: 10202159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D36B760247 for ; Tue, 6 Feb 2018 02:37:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC322289E3 for ; Tue, 6 Feb 2018 02:37:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE3FF289F2; Tue, 6 Feb 2018 02:37:05 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6268B289E3 for ; Tue, 6 Feb 2018 02:37:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752165AbeBFChD (ORCPT ); Mon, 5 Feb 2018 21:37:03 -0500 Received: from outgoing-stata.csail.mit.edu ([128.30.2.210]:44412 "EHLO outgoing-stata.csail.mit.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752141AbeBFChC (ORCPT ); Mon, 5 Feb 2018 21:37:02 -0500 Received: from 67-148-5-85.dia.static.qwest.net ([67.148.5.85] helo=[127.0.1.1]) by outgoing-stata.csail.mit.edu with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.82) (envelope-from ) id 1eiswZ-000R0f-NJ; Mon, 05 Feb 2018 21:25:11 -0500 Subject: [PATCH 1/2] char_dev: Fix off-by-one bugs in find_dynamic_major() From: "Srivatsa S. Bhat" To: gregkh@linuxfoundation.org, logang@deltatee.com Cc: axboe@kernel.dk, jlayton@poochiereds.net, bfields@fieldses.org, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, srivatsa@csail.mit.edu Date: Mon, 05 Feb 2018 18:25:09 -0800 Message-ID: <151788389652.28069.6065922071875812126.stgit@srivatsa-ubuntu> User-Agent: StGit/0.18 MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Srivatsa S. Bhat CHRDEV_MAJOR_DYN_END and CHRDEV_MAJOR_DYN_EXT_END are valid major numbers. So fix the loop iteration to include them in the search for free major numbers. While at it, also remove a redundant if condition ("cd->major != i"), as it will never be true. Signed-off-by: Srivatsa S. Bhat Reviewed-by: Logan Gunthorpe --- fs/char_dev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/char_dev.c b/fs/char_dev.c index a65e4a5..33c9385 100644 --- a/fs/char_dev.c +++ b/fs/char_dev.c @@ -67,18 +67,18 @@ static int find_dynamic_major(void) int i; struct char_device_struct *cd; - for (i = ARRAY_SIZE(chrdevs)-1; i > CHRDEV_MAJOR_DYN_END; i--) { + for (i = ARRAY_SIZE(chrdevs)-1; i >= CHRDEV_MAJOR_DYN_END; i--) { if (chrdevs[i] == NULL) return i; } for (i = CHRDEV_MAJOR_DYN_EXT_START; - i > CHRDEV_MAJOR_DYN_EXT_END; i--) { + i >= CHRDEV_MAJOR_DYN_EXT_END; i--) { for (cd = chrdevs[major_to_index(i)]; cd; cd = cd->next) if (cd->major == i) break; - if (cd == NULL || cd->major != i) + if (cd == NULL) return i; }