Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9C603C7EE23 for ; Wed, 7 Jun 2023 07:44:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.544416.850194 (Exim 4.92) (envelope-from ) id 1q6nqI-0007j2-8R; Wed, 07 Jun 2023 07:44:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 544416.850194; Wed, 07 Jun 2023 07:44:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q6nqI-0007it-5W; Wed, 07 Jun 2023 07:44:30 +0000 Received: by outflank-mailman (input) for mailman id 544416; Wed, 07 Jun 2023 07:44:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q6nqG-0007ht-O1 for xen-devel@lists.xenproject.org; Wed, 07 Jun 2023 07:44:29 +0000 Received: from bombadil.infradead.org (bombadil.infradead.org [2607:7c80:54:3::133]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2099ec7c-0507-11ee-b232-6b7b168915f2; Wed, 07 Jun 2023 09:44:27 +0200 (CEST) Received: from hch by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q6nqB-004n5l-03; Wed, 07 Jun 2023 07:44:23 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2099ec7c-0507-11ee-b232-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=4Sx6PZ8z7yUHSRyrSyhfNlQuLMPtcylN+zdcdoTWpXg=; b=KEHhRRtM/7119LZoHZ21PYKQvf oxQ3RW7h1hm22BBehjrTIxZs+Hq4vNo2r7l6s04yZHqhXriMF63WHd9i5/zDyUJLhCmuIXXizFHjF 4Jsv/ky6uLqB5DrYaMtEapqpJJHQIp+5COiFf/fjdAb68jrejI06b4/3yOXZm25RDROV2sLsCI7/M LzYuzlMAcsstPZ3ok7GYLmLvIlnHuHYvruYjB+JVdJQz2zhH7pKYEIBJ1kQdE+vY6qsnVevIkJy2M ta9L6kYnOflYPdvVBtihfIYaqAzWLOjNSQvLp3cM2kFEDfgTrtzUdL7vORwRcQ+gVauExyOPeEpbw JiOgiSfQ==; Date: Wed, 7 Jun 2023 00:44:22 -0700 From: Christoph Hellwig To: Demi Marie Obenour Cc: Roger Pau =?iso-8859-1?Q?Monn=E9?= , Jens Axboe , Marek =?iso-8859-1?Q?Marczykowski-G=F3recki?= , xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] xen-blkback: Implement diskseq checks Message-ID: References: <20230601214823.1701-1-demi@invisiblethingslab.com> <20230601214823.1701-2-demi@invisiblethingslab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230601214823.1701-2-demi@invisiblethingslab.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html On Thu, Jun 01, 2023 at 05:48:22PM -0400, Demi Marie Obenour wrote: > + if (diskseq) { > + struct gendisk *disk = bdev->bd_disk; > + > + if (unlikely(disk == NULL)) { > + pr_err("%s: device %08x has no gendisk\n", > + __func__, vbd->pdevice); > + xen_vbd_free(vbd); > + return -EFAULT; > + } bdev->bd_disk is never NULL. > + diskseq_str = xenbus_read(XBT_NIL, dev->nodename, "diskseq", &diskseq_len); Please avoid the overly long line. > + if (IS_ERR(diskseq_str)) { > + int err = PTR_ERR(diskseq_str); > + diskseq_str = NULL; > + > + /* > + * If this does not exist, it means legacy userspace that does not .. even more so in comments. > + * support diskseq. > + */ > + if (unlikely(!XENBUS_EXIST_ERR(err))) { > + xenbus_dev_fatal(dev, err, "reading diskseq"); > + return; > + } > + diskseq = 0; > + } else if (diskseq_len <= 0) { > + xenbus_dev_fatal(dev, -EFAULT, "diskseq must not be empty"); > + goto fail; > + } else if (diskseq_len > 16) { No need for a else after a return. > + xenbus_dev_fatal(dev, -ERANGE, "diskseq too long: got %d but limit is 16", > + diskseq_len); > + goto fail; > + } else if (diskseq_str[0] == '0') { > + xenbus_dev_fatal(dev, -ERANGE, "diskseq must not start with '0'"); > + goto fail; > + } else { > + char *diskseq_end; > + diskseq = simple_strtoull(diskseq_str, &diskseq_end, 16); > + if (diskseq_end != diskseq_str + diskseq_len) { > + xenbus_dev_fatal(dev, -EINVAL, "invalid diskseq"); > + goto fail; > + } > + kfree(diskseq_str); > + diskseq_str = NULL; > + } And I suspect the code will be a lot easier to follow if you move the diskseq validation into a separate helper.