Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp382463rwd; Wed, 7 Jun 2023 00:58:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mAiqU5Mjv2mVlD6TcEizggcE7nTUDmOdvOfeqyZI/ivhuWRxqi+WUuVd8V68bL8pgbO+A X-Received: by 2002:a0d:d891:0:b0:565:9a3d:a3f9 with SMTP id a139-20020a0dd891000000b005659a3da3f9mr6464219ywe.9.1686124733730; Wed, 07 Jun 2023 00:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686124733; cv=none; d=google.com; s=arc-20160816; b=JbmBGaZwRVyW0lej/iJaYSfmO/dJbNenhggTUjb87ckUwv9s417SWNNoKPyLcYRK1o sqjJj6wystVSTjw+VSvMEGgVwqnua4Oe9xldDtQJLQYVdseVuqAsVjZW8A6j+1wXywx7 DDS9cGq+3QAEMJnI6+oEX+UtcjARmG16sf66LtpwLohbvwGMbSzWUeqJCeqx9r4Xv0ZP o8Es9+tZirt4Tml3Hr/N7Lu8qrOVfmEFPHnB4sgzlLaDFgoEKxZEH7/shfYQalSR2XVa IDxNNt/eMg2vScCeCbL1Okpx4qTsHiuzbrD+OeiflewPTpAO8ot4b+BtckxJoHSn1zZI Pbtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4Sx6PZ8z7yUHSRyrSyhfNlQuLMPtcylN+zdcdoTWpXg=; b=k8NAaVxGDf97zPNvHwqkZuqWS2c9YL15QPkuIEkgfa/uk8Hitzp++wJTieAxZbaMFg 0Jbvu4NX0V8pH7J/d8kSvO1mzpVfn42Ryn8AjyF66giObUQ6eCrZe1OxV0j2jg6K5rpc /F0EmdM6T32kpyj706GICIp6NQ38/QYjkrUozTguO7aOvuyH87XZ8/lvJkKxLD5YDxYi GRxiIRnHrzKizvJBXbEIMA9r0lq7146nMzrMXWrfWpZrk+YtWWMujNui/Je0zHhs7Wl/ +TQmuRIXjNRXqNDFIokvSWsh6SgD+SuPBHZsbQ6NBZxWSlrTxq5eQSrKXbJX3oDJykUG UMng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=KEHhRRtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b143-20020a621b95000000b0064d5b6864d0si8136960pfb.76.2023.06.07.00.58.39; Wed, 07 Jun 2023 00:58:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=KEHhRRtM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239328AbjFGHqm (ORCPT + 99 others); Wed, 7 Jun 2023 03:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239850AbjFGHpy (ORCPT ); Wed, 7 Jun 2023 03:45:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CE3D2D65; Wed, 7 Jun 2023 00:44:26 -0700 (PDT) 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==; 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 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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.