Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6738390rdb; Tue, 2 Jan 2024 11:31:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVqljQ5VZp4Ia9FDEjL8QXhBZiXKqPDaipkVXC8wwZIMD3k2jS8TPUSEMIpMjhHFQb79fG X-Received: by 2002:a05:6a21:182:b0:197:65ff:8129 with SMTP id le2-20020a056a21018200b0019765ff8129mr260983pzb.27.1704223912824; Tue, 02 Jan 2024 11:31:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704223912; cv=none; d=google.com; s=arc-20160816; b=RBY15N0vViPlx/eEwtRVqqlTOPs57dYJmWSFtSe1eaSswDXpOK5F0U9AdE9b5OQQHe spO5HmDXo3OAA2LJvfLBrdN3D5rQxTTcIPf51/OCYtU5yzPNWIPpFEvvf/2HHmRRlYIc hnI2hY2KBaX++/a3grpnEj+JBloJktlzlNxies+Xy9ewMIIlJMJWkt441P+TY64IHMJL M4ZFi30sob0GS04d/Ka/VxvhhjGsQXZ/xwKJvZTlztNo1LqWbWbprcK8b1c7qZxGTUpc nSJsDkh+YfypA7TJmkkWR9J02H8TzNjQGPHTrn5f5qZM8y3Do6guAQ4uiTwzosqRW40W Ogtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=7ymrn+TqTuzRJ+1jVJo7GoiM3RInVGApx69USx9hL2s=; fh=gXo36jyJkn2+kLCy7e1AXHa3lqaFxPhn6wchE+3LGAE=; b=DheDMct2UeRrKNKI1N3ZBnL5DiyXaB7sL9tqI85RZd45i2h6UKeLTuHqiPibhm+oou UKfMintxpweUrh6T41m/T4oTiSyCaQtoS3WeR4ZHJFr0yZqynqM67bt+YuRW6F+mmcmW IW+6ff46wtJgbwRfHVqvvVKBEMvnzBYMX7LiTTb5IQk8HwyYbMGQTpmn0WEspW38ku25 8GUxC9zM0/q5M+T0oGJ+Yj7Hq5Jk7cCXN4zPvK2Dzdu197q5jSDNKPNO9efyIPRdLmEc iDoWxUURHwkF6CAaFiLsyOkFGvreSmNAxBk+r1a8/f0C+uAwQDWlg6wrwepI0Noi5nvY 7ADA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EPh7L4Hw; spf=pass (google.com: domain of linux-kernel+bounces-14775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14775-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t68-20020a625f47000000b006d98c793ebdsi17829855pfb.318.2024.01.02.11.31.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:31:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EPh7L4Hw; spf=pass (google.com: domain of linux-kernel+bounces-14775-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14775-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6CA25B22950 for ; Tue, 2 Jan 2024 19:31:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87A0715E99; Tue, 2 Jan 2024 19:31:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="EPh7L4Hw" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9DDF916400; Tue, 2 Jan 2024 19:31:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C833CC433C8; Tue, 2 Jan 2024 19:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1704223878; bh=PpLk4en3PtlVWanOtZnA79EAQW/E6LW7oiPi+rIhTNA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EPh7L4HwyIMY5uAmrct1hUT1x9Yd6UGYe6iZryQlAtjyyXi2g62Pxy0ZRO7vhWK7W H1aRiwc1bkii6twji3wm70/PYmDYLPnzpIGo0PebFpzhFNi1aGRkzHG5tdkCDJww+D Q99tIo5e+bBb5jlMMlJGiXI0ZF2PFttzFEdyamXw= Date: Tue, 2 Jan 2024 11:31:17 -0800 From: Andrew Morton To: Markus Elfring Cc: kernel-janitors@vger.kernel.org, Ahelenia =?UTF-8?Q?Ziemia=C5=84ska?= , Li kunyu , Michal Hocko , Sebastian Reichel , Suren Baghdasaryan , Zhang Zhengming , Zhou Kete , LKML Subject: Re: [PATCH] kernel: relay: Improve exception handling in relay_create_buf() Message-Id: <20240102113117.b2b4ffa2998eb51b674b0304@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 31 Dec 2023 10:38:10 +0100 Markus Elfring wrote: > From: Markus Elfring > Date: Sun, 31 Dec 2023 10:26:25 +0100 > > The kfree() function was called in one case by > the relay_create_buf() function during error handling > even if the passed data structure member contained a null pointer. > This issue was detected by using the Coccinelle software. > > Thus use another label. > > ... > > --- a/kernel/relay.c > +++ b/kernel/relay.c > @@ -161,14 +161,15 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan) > > buf->start = relay_alloc_buf(buf, &chan->alloc_size); > if (!buf->start) > - goto free_buf; > + goto free_padding; > > buf->chan = chan; > kref_get(&buf->chan->kref); > return buf; > > -free_buf: > +free_padding: > kfree(buf->padding); > +free_buf: > kfree(buf); > return NULL; > } kfree(NULL) is an OK thing to do, and is a well-known pattern. Can we arrange for Coccinelle to understand this?