Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1303629lqb; Thu, 18 Apr 2024 06:18:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXXvFpbK9wVLg733wqD91cqS0zVQUEbXgUVD/4N1G5fsHcH4OUrn+KVPewQL88hRKmosaEalYjrM2mcU7KPhLNOH5N6GxyBifeBWPNBfA== X-Google-Smtp-Source: AGHT+IG7sAeyiWx9owunLuHlbg+QhN8pYGxbwNQEB8gu0OKrBdKipo3wV+aX5Zyp9XwvtDs6JxDH X-Received: by 2002:a05:6122:411e:b0:4d4:1cca:1a72 with SMTP id ce30-20020a056122411e00b004d41cca1a72mr3041977vkb.6.1713446334182; Thu, 18 Apr 2024 06:18:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713446334; cv=pass; d=google.com; s=arc-20160816; b=Ues/5vM1f4G6Tn4A7DHAzlydTNfRZpsoryAjfNDxXPODdbM/wOKZWm4JlhHsGIyY+J 9FZ2USN9esfX/v7anbDobuCZLT0MKqix/kGpIbazU0v3C/s1472GRPfps6Mz9aJlRm80 ui1tuyms7d1CglEjDcX4Twx0MLbIo1n3cjJ5CuiPF5T9M/AyBLmeXGEXy2bUS665JZ9J CKVatnAg3o65ZDtLB2cPAxION3REmUjg4ClPf6igSVIRO47s3/iMhyhILcyLTg+98ynO r0Lk06zLgQJ7Ie285LztCqjl4XZ7feNYvWdPI1HG+S6ADHPMiSxIcAssdc3Lcp2ue/7j Bzjg== ARC-Message-Signature: i=2; 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 :date:subject:cc:to:from:dkim-signature; bh=2lvDVBn2YeHNhWXJQKj2GHQDBwVBzUZ6NZWRt9eEEeI=; fh=09M2aIUk217xVHHSKfJvC8gudmLoJFMlq58sm+GC4Qo=; b=E99/lq8SdPnrZ2d55kJHFw9rUjEAMSXUWOd0dmEziKe9U0tuJ1YxxrP1bqxEjE1c/Q A/YPuWVDpspdaGFEgVprMiNEvdqyK8U9njcRxHE35nWzxPa0yKyMRhj9XFInabPwEbo6 3m5imywZ/UfnE9fU+eVDls9oUo/KKPkdOOwVMfPnHBSVaJATA5fimfYVw4KyIvdI2RHB gr3GtstnUXIYR5YA+ZWQMPhDRJoiNFZuJBf/vpxXD0/eqQT2izBYftnlcR6bPchQeBsu OHJdd8A77g0YZHkCzQ6lZim+5zDJXWLreuFCDfEc1UkvSFBihPJznL2HZX2Q16wA6sE5 XEIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SiD671Ke; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-150152-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150152-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 1-20020ac5ce81000000b004daaa8bbe46si206530vke.82.2024.04.18.06.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 06:18:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150152-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SiD671Ke; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-150152-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150152-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BC2C11C20F08 for ; Thu, 18 Apr 2024 13:18:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87DCE1635B2; Thu, 18 Apr 2024 13:18:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SiD671Ke" 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 3256816133C for ; Thu, 18 Apr 2024 13:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713446292; cv=none; b=L22QWZ67OPA/LAG0hyk00r7p1G1ztrArC0f/mRhTv7p500i9O2Hke/3mhumFNYNbFcIpxFrASQFY4rrVGGzZdjizHuNZ42MnxSaJ8d95AksMJWZxewSgH7Vp9Chc03oHOtqF2VlZOX1bQCIrAuPWd3uZtxMBdHTOmNTyN9gUTU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713446292; c=relaxed/simple; bh=Ivl7NLRFYxtoqjJkKe1UCiz86XgKw2dJ0dlF8yqQUlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iOeQ+S9QfU6wbk8o5smcjqqq+16yOm6PTbseHHGTUTmWcOXYXbdltw0kQ4m4LWWYcWSb/H0VgI3374kyOwYB6k1bY5UCffB/5V+lUV1Nj/gDTZ9RV04cH+O4KLyAPDB0ExrOqdzpB4BIXzxp4Pdq4bMfbtG9h0dWdOAMXwwNZxQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SiD671Ke; arc=none smtp.client-ip=170.10.133.124 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=1713446290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2lvDVBn2YeHNhWXJQKj2GHQDBwVBzUZ6NZWRt9eEEeI=; b=SiD671KeZZ8QtKjFHxDEIxxI/T47BMLhFXeVTQRjvIWE3VC2ufPK4gvH3Q/TtjTQTbKt/a iCRjx4As4CFj65+fG/PTDNB+kiDTQrY/827uVx6warFJIPBohhAFhAuv+4LsOg0cLdut02 hzh8OZ4Vw+IiZ1cVqSG9yKwdB7vtr4k= 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-142-0KBN1d59MpKjGWi_1t5Ugw-1; Thu, 18 Apr 2024 09:18:06 -0400 X-MC-Unique: 0KBN1d59MpKjGWi_1t5Ugw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 C829A3C23FD0; Thu, 18 Apr 2024 13:18:05 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.16.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9D37C271A4; Thu, 18 Apr 2024 13:18:03 +0000 (UTC) From: Wander Lairson Costa To: Brendan Higgins , David Gow , Rae Moar , linux-kselftest@vger.kernel.org (open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)), kunit-dev@googlegroups.com (open list:KERNEL UNIT TESTING FRAMEWORK (KUnit)), linux-kernel@vger.kernel.org (open list) Cc: Wander Lairson Costa Subject: [PATCH 2/2] kunit: avoid memory leak on device register error Date: Thu, 18 Apr 2024 10:17:53 -0300 Message-ID: <20240418131754.58217-3-wander@redhat.com> In-Reply-To: <20240418131754.58217-1-wander@redhat.com> References: <20240418131754.58217-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 If the device register fails, free the allocated memory before returning. Signed-off-by: Wander Lairson Costa --- 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); return ERR_PTR(err); } -- 2.44.0