Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6760521rdb; Tue, 2 Jan 2024 12:21:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiwHSH7nYhfgDJczRQE0JkRoni1kS7sp9gzKInQQy9+T8QyYbvv60pUnquVi3Kbg7omLFP X-Received: by 2002:a05:600c:198c:b0:40d:5a23:3d90 with SMTP id t12-20020a05600c198c00b0040d5a233d90mr3320454wmq.91.1704226912741; Tue, 02 Jan 2024 12:21:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704226912; cv=none; d=google.com; s=arc-20160816; b=gNWFzqEqW/Vjkh9W+Psw6E7QWFJO2b4yjd6oy2mT48jsI12c/y01ZNaOwrsLubmWEa vSl150zT8czLWidulyQvHsnk6OVtH8GaElI5r7UoSB/DUPEnIv8DanJIniMOMI3fO/0U CSKkY1AeCaOOCnzZgI00LwTfWc9LvvFdbdLqgkNC8b/4EOFv4oQid0TXwQjY/MLQQOz6 ghZnjokYsZO7jLardEbo+2qxy9RJ/ge4eMDKn491rIPDtz0RYJE0dn31xa8BV/k0UMKs qDlbqDYY+38pnkjJq6SwXTNuqdOw29AGcx3mzqUObaGnLWbYRP4wvNVha46u1S4DlFzY rFfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mf+A2l9BZ4h/BUGC6R/qVkbg+mOP6JOePma0+l5vK88=; fh=c+q1WHHdWdW6vnVufftC6suPP97EqJtW2r690h5lvkM=; b=EhtfkIU9FuxEDZnijrlyuRIjKICEc2Yq2226AYVeluqnWhzk66hmB1q1gtBujt0vRA Sb7S8OMPSYQZ0lAWv9B3ffJ8MfghkpF+tB3WiUH11mxvnxyoMoes/D/K9atz4Cz+ZYaM 3HH3ggT4kQa8bioDI7FV+bV+e7mA9uc3i9Uyst0BLF5YSrIFS1cAXmbAno94bR1TFrKy qntti3QOJ0Q/ePwwgiPOesL+OY+8yFTW0WOlgrnIT25pCY7Iw5F9Ae9t/y/W6q2N6f+I 6RfXPjn0TgB7u/dE61d1XK3z3gl3o8ynmF0La3E4u5dyZfzh6a9CbuaIu9JJgETOWAj/ matw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hg+K6B1D; spf=pass (google.com: domain of linux-kernel+bounces-14799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ew20-20020a170907951400b00a26b023ba62si9495195ejc.152.2024.01.02.12.21.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 12:21:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hg+K6B1D; spf=pass (google.com: domain of linux-kernel+bounces-14799-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14799-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5328D1F234F6 for ; Tue, 2 Jan 2024 20:21:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 958011640B; Tue, 2 Jan 2024 20:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hg+K6B1D" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4533C1640A for ; Tue, 2 Jan 2024 20:21:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704226898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mf+A2l9BZ4h/BUGC6R/qVkbg+mOP6JOePma0+l5vK88=; b=hg+K6B1DXAT8zyTslxvKMsNUB7iuj3on8qaEvsgCwg+cgKmO4jVXCcoCjsZvcf80eXGGsX SSaqQSD1EC8Pwl/62DqvlmF0LcmK/JOPk9m2G8NXqdh+tilL0Arb9D1BM3z+NQW75ONPLZ aeNwTRldqi0G0Qyc9qrHAQQPTe8CJm8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-UkVYTtcVN_K3sGanpLGXSw-1; Tue, 02 Jan 2024 15:21:35 -0500 X-MC-Unique: UkVYTtcVN_K3sGanpLGXSw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A9413C0E644; Tue, 2 Jan 2024 20:21:35 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.16.212]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 982691C060AF; Tue, 2 Jan 2024 20:21:34 +0000 (UTC) Received: by fedora.redhat.com (Postfix, from userid 1000) id A6B1428C5E5; Tue, 2 Jan 2024 15:21:33 -0500 (EST) Date: Tue, 2 Jan 2024 15:21:33 -0500 From: Vivek Goyal To: Markus Elfring Cc: virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, kernel-janitors@vger.kernel.org, Miklos Szeredi , Stefan Hajnoczi , LKML , Matthew Wilcox Subject: Re: [PATCH 2/2] virtiofs: Improve error handling in virtio_fs_get_tree() Message-ID: References: <5745d81c-3c06-4871-9785-12a469870934@web.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5745d81c-3c06-4871-9785-12a469870934@web.de> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 On Fri, Dec 29, 2023 at 09:38:47AM +0100, Markus Elfring wrote: > From: Markus Elfring > Date: Fri, 29 Dec 2023 09:15:07 +0100 > > The kfree() function was called in two cases by > the virtio_fs_get_tree() function during error handling > even if the passed variable contained a null pointer. > This issue was detected by using the Coccinelle software. > > * Thus use another label. > > * Move an error code assignment into an if branch. > > * Delete an initialisation (for the variable “fc”) > which became unnecessary with this refactoring. > > Signed-off-by: Markus Elfring As Matthew said that kfree(NULL) is perfectly acceptable usage in kernel, so I really don't feel that this patch is required. Current code looks good as it is. Thanks Vivek > --- > fs/fuse/virtio_fs.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c > index 2f8ba9254c1e..0746f54ec743 100644 > --- a/fs/fuse/virtio_fs.c > +++ b/fs/fuse/virtio_fs.c > @@ -1415,10 +1415,10 @@ static int virtio_fs_get_tree(struct fs_context *fsc) > { > struct virtio_fs *fs; > struct super_block *sb; > - struct fuse_conn *fc = NULL; > + struct fuse_conn *fc; > struct fuse_mount *fm; > unsigned int virtqueue_size; > - int err = -EIO; > + int err; > > /* This gets a reference on virtio_fs object. This ptr gets installed > * in fc->iq->priv. Once fuse_conn is going away, it calls ->put() > @@ -1431,13 +1431,15 @@ static int virtio_fs_get_tree(struct fs_context *fsc) > } > > virtqueue_size = virtqueue_get_vring_size(fs->vqs[VQ_REQUEST].vq); > - if (WARN_ON(virtqueue_size <= FUSE_HEADER_OVERHEAD)) > - goto out_err; > + if (WARN_ON(virtqueue_size <= FUSE_HEADER_OVERHEAD)) { > + err = -EIO; > + goto lock_mutex; > + } > > err = -ENOMEM; > fc = kzalloc(sizeof(*fc), GFP_KERNEL); > if (!fc) > - goto out_err; > + goto lock_mutex; > > fm = kzalloc(sizeof(*fm), GFP_KERNEL); > if (!fm) > @@ -1476,6 +1478,7 @@ static int virtio_fs_get_tree(struct fs_context *fsc) > > out_err: > kfree(fc); > +lock_mutex: > mutex_lock(&virtio_fs_mutex); > virtio_fs_put(fs); > mutex_unlock(&virtio_fs_mutex); > -- > 2.43.0 >