From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E15BCC5519F for ; Wed, 18 Nov 2020 09:11:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 53918246A7 for ; Wed, 18 Nov 2020 09:11:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Nx+h2rhZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 53918246A7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D09B96B007B; Wed, 18 Nov 2020 04:11:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CBC276B007D; Wed, 18 Nov 2020 04:11:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCF956B007E; Wed, 18 Nov 2020 04:11:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id 914006B007B for ; Wed, 18 Nov 2020 04:11:52 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 41693A8C0 for ; Wed, 18 Nov 2020 09:11:52 +0000 (UTC) X-FDA: 77496971664.13.neck49_3504c6927339 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 2470F18140B60 for ; Wed, 18 Nov 2020 09:11:52 +0000 (UTC) X-HE-Tag: neck49_3504c6927339 X-Filterd-Recvd-Size: 5013 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Nov 2020 09:11:51 +0000 (UTC) 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=AZC0zIud/sy36HL3UqpdhruuJxaP+dAsE+XWl7N2xio=; b=Nx+h2rhZg/HvIdxi/V4Jhb3r0u Ha9RMCfuFy1DcNiHVfggBRgvESO9x7+pxSBvldUugXJje0PXHGlc4RwDDAg7KizNUutdw1Oz6YYyv GW4iMGk2/W7s5u9pbxqjoSdBjJixbVkMGKI4sJ3RWvWoE3K0iOy/pbqDa1e1ML4CIGcPuaXqz2g9g GWC0Sp67FA+/219oiqS3gSXWZE8BQ1pE8WMHKNGls47Mx8ZIwmqDOxT3eb3qNMpqy/o6N2LhYhPo2 rajpeTK4bPGzZuMUv7onhX7MqP2bpqaR14FcEdjZKriDz9DBejg943e2dL+oCaa6VfesI9rxujAcy PLSuDG6w==; Received: from [2001:4bb8:18c:31ba:32b1:ec66:5459:36a] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfJ8S-0007lc-Hx; Wed, 18 Nov 2020 08:48:16 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Tejun Heo , Josef Bacik , Konrad Rzeszutek Wilk , Coly Li , Mike Snitzer , dm-devel@redhat.com, Richard Weinberger , Jan Kara , linux-block@vger.kernel.org, xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 08/20] init: refactor devt_from_partuuid Date: Wed, 18 Nov 2020 09:47:48 +0100 Message-Id: <20201118084800.2339180-9-hch@lst.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201118084800.2339180-1-hch@lst.de> References: <20201118084800.2339180-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The code in devt_from_partuuid is very convoluted. Refactor a bit by sanitizing the goto and variable name usage. Signed-off-by: Christoph Hellwig --- init/do_mounts.c | 68 ++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/init/do_mounts.c b/init/do_mounts.c index aef2f24461c7f1..afa26a4028d25e 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -105,13 +105,10 @@ static int match_dev_by_uuid(struct device *dev, co= nst void *data) */ static dev_t devt_from_partuuid(const char *uuid_str) { - dev_t res =3D 0; struct uuidcmp cmp; struct device *dev =3D NULL; - struct gendisk *disk; - struct hd_struct *part; + dev_t devt =3D 0; int offset =3D 0; - bool clear_root_wait =3D false; char *slash; =20 cmp.uuid =3D uuid_str; @@ -120,52 +117,49 @@ static dev_t devt_from_partuuid(const char *uuid_st= r) /* Check for optional partition number offset attributes. */ if (slash) { char c =3D 0; + /* Explicitly fail on poor PARTUUID syntax. */ - if (sscanf(slash + 1, - "PARTNROFF=3D%d%c", &offset, &c) !=3D 1) { - clear_root_wait =3D true; - goto done; - } + if (sscanf(slash + 1, "PARTNROFF=3D%d%c", &offset, &c) !=3D 1) + goto clear_root_wait; cmp.len =3D slash - uuid_str; } else { cmp.len =3D strlen(uuid_str); } =20 - if (!cmp.len) { - clear_root_wait =3D true; - goto done; - } + if (!cmp.len) + goto clear_root_wait; =20 - dev =3D class_find_device(&block_class, NULL, &cmp, - &match_dev_by_uuid); + dev =3D class_find_device(&block_class, NULL, &cmp, &match_dev_by_uuid)= ; if (!dev) - goto done; - - res =3D dev->devt; + return 0; =20 - /* Attempt to find the partition by offset. */ - if (!offset) - goto no_offset; + if (offset) { + /* + * Attempt to find the requested partition by adding an offset + * to the partition number found by UUID. + */ + struct hd_struct *part; =20 - res =3D 0; - disk =3D part_to_disk(dev_to_part(dev)); - part =3D disk_get_part(disk, dev_to_part(dev)->partno + offset); - if (part) { - res =3D part_devt(part); - put_device(part_to_dev(part)); + part =3D disk_get_part(dev_to_disk(dev), + dev_to_part(dev)->partno + offset); + if (part) { + devt =3D part_devt(part); + put_device(part_to_dev(part)); + } + } else { + devt =3D dev->devt; } =20 -no_offset: put_device(dev); -done: - if (clear_root_wait) { - pr_err("VFS: PARTUUID=3D is invalid.\n" - "Expected PARTUUID=3D[/PARTNROFF=3D%%d]\n"); - if (root_wait) - pr_err("Disabling rootwait; root=3D is invalid.\n"); - root_wait =3D 0; - } - return res; + return devt; + +clear_root_wait: + pr_err("VFS: PARTUUID=3D is invalid.\n" + "Expected PARTUUID=3D[/PARTNROFF=3D%%d]\n"); + if (root_wait) + pr_err("Disabling rootwait; root=3D is invalid.\n"); + root_wait =3D 0; + return 0; } =20 /** --=20 2.29.2