Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp666344lqt; Fri, 19 Apr 2024 07:07:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhOvK1w+7IfLRDza7EF3kjAjuR4rRLSV7pDX4/Ng0SjV+9ZNrlG9V1sbOK1y+kmva7i9k7WvmKMh1sa6qkbKfmp3ykuQh9OIEz7EzwmQ== X-Google-Smtp-Source: AGHT+IHMCAd3hnySE5/Mr8tbSXIiWcF//VWuS2cYG2Joz2hKZCBcsliFYSULBErKx3obJHK3I1lv X-Received: by 2002:a17:90a:840e:b0:2a6:43c:44c6 with SMTP id j14-20020a17090a840e00b002a6043c44c6mr2199536pjn.29.1713535667430; Fri, 19 Apr 2024 07:07:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713535667; cv=pass; d=google.com; s=arc-20160816; b=FbnskxibklfRihTBPBZetNvbdyqwBJFNt66t08B/iOQTs1J4X95AQxYN9v035wG6Oj 4iDZDkWC4BUrhjlRxaftMgFxH1N3H8F9SP+S7mR2qzjkE9/ba2yNQOO8m+lvJVvtdC7w wNf4XBZg2XSbOD5p6Wg5DTk8azbcVNjgZ4RsrTwy3OrHpjUt7nliaJwfguOknMsiySTp OxUAv5CWmxh4JMbNekaRudgcZqDkQT0VWyCDpxvr2IsJYxLhFSKV70F4QnIF0ad1VrsO BEwF7D+sxyA07MnuUG1bOaGNafO5MXfa+wv9q41hsSwXDriLDb36BRnDjKCpHrB3H6fG a7Kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hfgCBemowhnHYQewHKa7nBfx8HxqZOLZhaGehHF3u4w=; fh=vfUnn1S50MuGbnCSlYjSxC9qoP6oi2GbMJ2PVKs9je0=; b=HaCyp+9ZT2thdlBxZi19Y20mNVkAsocojxt0vDMPtqRCZWFc52OzqSpcpqC54nVNxj j5yE4nGoJq5Jbnbw3s/KpVxmH3md0F/7ZsilHZdaDIMLFFchMPZsvFtOvILTrWbZZAd6 bXDZJaH8GsWZj6ADX4lGEHOyrtdvrFq1aH1b8O20RtTVB8dglCwfd82JcomU1IFZ/Jlj tC1svoXJSjsTbkTSQZD3uWnJJ7QRWVuIYf1wfAXxDaVySysASDIWRoDXNeY2tNsNjsAj ZWVh5PixTwzRkxiInEg/allgE7qgyK60NqryVhxAlOzCKgZL8P23H65+2AekYF64jvE+ XKrA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CyP3Up9R; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-151536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d8-20020a17090a498800b002a528a1bfb0si3311785pjh.20.2024.04.19.07.07.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 07:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CyP3Up9R; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-151536-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151536-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AD389284F83 for ; Fri, 19 Apr 2024 14:06:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFE9E133994; Fri, 19 Apr 2024 14:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CyP3Up9R" 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 D31EB12DDB5; Fri, 19 Apr 2024 14:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713535398; cv=none; b=Bs/RrJMRqzx4/RR7t2zmcDO+yPF5NF+GsCVEnMyztqlN/3ubdcAHmNxhfWAbv6EVeNL+0BtJVm/ApaB4WFixMIvqRn5vcPJZ+BAyd59Whtqp5mgeKNrfD2cUokqAhEeumo8QoZSLDtkYfiLhz288W4nMn4kPOWktUWPAkebG+6U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713535398; c=relaxed/simple; bh=eqH1aWQ6y/Xs4N8czYfOUVDZDBYeQAX8RmC4mrbUQ/w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=G89JImTinwhZOVSyiBdV9BZkRzUpmIgj21o/JS5jneCX+irQ6NfFF8TNlFjnAX4p26WXiErX831EVAeAUFmveW134jLL8lz4rhmAwr+Ny9u3POZBR7Ysrfz+3S+T0Ruag6/4scr6jBAFmJ2P2fP0TvpKy2VpiNRvPvkCMBjWQs4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CyP3Up9R; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1289C072AA; Fri, 19 Apr 2024 14:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1713535398; bh=eqH1aWQ6y/Xs4N8czYfOUVDZDBYeQAX8RmC4mrbUQ/w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CyP3Up9RAJLx2lV2njOvVE8wUKiOVSmu0sNiuYLvY2i6JwtnEtuKBqIja8paozH9B SUdvZ2TbG4jRhKjZG5sraOoFIiLy0AhqrUFoInVBoflMqpApyNU0hCt3uNpywlyRA4 PhMO+gMAazCTgtSHiirq798YLSnYjSovt464SiaY= Date: Fri, 19 Apr 2024 16:03:12 +0200 From: Greg Kroah-Hartman To: Wander Lairson Costa Cc: Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Matti Vaittinen , Maxime Ripard , "open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)" , "open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)" , open list Subject: Re: [PATCH v4 2/2] kunit: avoid memory leak on device register error Message-ID: <2024041919-unify-improve-d4a5@gregkh> References: <20240419132504.9488-1-wander@redhat.com> <20240419132504.9488-3-wander@redhat.com> 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-Disposition: inline In-Reply-To: <20240419132504.9488-3-wander@redhat.com> On Fri, Apr 19, 2024 at 10:25:02AM -0300, Wander Lairson Costa wrote: > If the device register fails, free the allocated memory before > returning. > > Signed-off-by: Wander Lairson Costa > Fixes: d03c720e03bd ("kunit: Add APIs for managing devices") > --- > lib/kunit/device.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/lib/kunit/device.c b/lib/kunit/device.c > index 25c81ed465fb..d8c09dcb3e79 100644 > --- a/lib/kunit/device.c > +++ b/lib/kunit/device.c > @@ -131,6 +131,7 @@ static struct kunit_device *kunit_device_register_internal(struct kunit *test, > err = device_register(&kunit_dev->dev); > if (err) { > put_device(&kunit_dev->dev); > + kfree(kunit_dev); This still looks wrong, the release function for the device should free the memory here, not this kfree, as the reference count in the embedded 'struct device' handles the memory logic for the whole structure (if not, then something is REALLY wrong...) You _do_ have a release function for the device, right? If not, you should be getting loud messages in the kernel log when releasing a device here. thanks, greg k-h