From nobody Sat May 18 08:14:05 2024 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 99632128806 for ; Fri, 19 Apr 2024 13:25:25 +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=1713533127; cv=none; b=Oy4Hr/VjfX/IYoiZUJXljsgH6cvMKc3JC2vpkjuvENBD2Uc62lUQ4mx2tAnQbbjj7Mpst9Ag9FRHbp6br3Kz0NW322VPc4apfUk/1g43JDkCtrX619h38cwqk8Uh148W5RnZpKQbdEBHKw+lHFW/EA0OBCJEuVnFU9Jghmi0Egs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713533127; c=relaxed/simple; bh=RkC57Q7UJKwDbV5ZOymkImc73C43dsfw8U713gEUT98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NimRvWxAyaXrgyQ+ItmkFS77+rWGQdUTLHTz9emUK6LOgq3jK6aczhdmMCMbA0MVGRDQ0SqtlFal/Pk/SI9QBmhncxsajeT6s41+NZiZ4yQEnXxe+5f7+cTjYY5xk7+L7At6jdEbpvIV8z5zCDpKoKzBMmHf8+P28eHm4eK1Dxw= 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=VezHzNXr; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VezHzNXr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713533123; 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=OquLsmPZLgQdNvdRfcQqVZOgi9jZ8SYqH65xHdO5f8w=; b=VezHzNXrNAGlFNH71SSPZGy+kuOW1S4ChuEGAEHl4ubxYoz7ai3HI4dlM6vYLxJK8b6SX3 dciviTbgbte2JE6Z0rLj+PUQmUD6CZcxaA8GvM00PQvj9ic5rY2H5ac7Lo6AuL/fNnwBi+ nkF7WHsy8EavMibPwSFccIQQOSMxB6I= 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-438-P4R0S8H_OU-wMgWfzGhtvg-1; Fri, 19 Apr 2024 09:25:18 -0400 X-MC-Unique: P4R0S8H_OU-wMgWfzGhtvg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 336753804516; Fri, 19 Apr 2024 13:25:16 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.8.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5D0A4EA62; Fri, 19 Apr 2024 13:25:12 +0000 (UTC) From: Wander Lairson Costa To: Brendan Higgins , David Gow , Rae Moar , Matti Vaittinen , Shuah Khan , Greg Kroah-Hartman , Maxime Ripard , 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 v4 1/2] kunit: unregister the device on error Date: Fri, 19 Apr 2024 10:25:01 -0300 Message-ID: <20240419132504.9488-2-wander@redhat.com> In-Reply-To: <20240419132504.9488-1-wander@redhat.com> References: <20240419132504.9488-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" kunit_init_device() should unregister the device on bus register error, but mistakenly it tries to unregister the bus. Unregister the device instead of the bus. Signed-off-by: Wander Lairson Costa Fixes: d03c720e03bd ("kunit: Add APIs for managing devices") Reviewed-by: Greg Kroah-Hartman --- lib/kunit/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kunit/device.c b/lib/kunit/device.c index abc603730b8e..25c81ed465fb 100644 --- a/lib/kunit/device.c +++ b/lib/kunit/device.c @@ -51,7 +51,7 @@ int kunit_bus_init(void) =20 error =3D bus_register(&kunit_bus_type); if (error) - bus_unregister(&kunit_bus_type); + root_device_unregister(kunit_bus_device); return error; } =20 --=20 2.44.0 From nobody Sat May 18 08:14:05 2024 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 C3BED83A14 for ; Fri, 19 Apr 2024 13:25:25 +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=1713533127; cv=none; b=jWEOs4c2aMi5Iy6tU534AeM50M2PaNGxcks+bxqIuUd4791yhaRO7TkrUusxTSKwmTiH0PIH0yhm9NLsmJ8zdKM+CoWvV8OUMAvK0FfZxdo3W8LihvapHRswjmAj03QIjQPU7h9nevSV0kBbTx2HwDGrnTpo+YoDcfZGqWG8X/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713533127; c=relaxed/simple; bh=zmdkTFihWpy+XhiLb7Ai9Fv3Kxr9kNr6UrAO97Mor0M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dVY5DIR3CsuLmvAK+zBjASs83qOV4YftTB43yx+k2G1jVzENs/JB1MAdIm8OtZEcvr5I2MCm5nPOwHrHedfdqfXKLBkJPEff2Ph7fIKQJo4hwOchM24Rim1OA3RIa+JQ1e/6InsKY6gJ1t9vBHZJ0nmh6kCE8gyC1Q68hBALe/c= 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=F4ok1DKx; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="F4ok1DKx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713533124; 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=QKFWmD89ZfxI3WrGZY3k5MGYxU+9FObI37ylz+l21us=; b=F4ok1DKxR9Klf0PXKQsyjF8Ij+v8XB76cl+rOY92vtlHqfrxEDGdxDeJopdX2W/T+rPAiI gZ+rCD9KQgls05yO/TO4DMYrHXCItf/UgA9l0woXcSDAzDu6EqVFhwoGz4jzPfanu9lp9k LuMvbpKFlYetw5FHA7dQDPx4dXMbdAQ= 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-286-xs4GAnh4PMSaDOM1y3cvUg-1; Fri, 19 Apr 2024 09:25:21 -0400 X-MC-Unique: xs4GAnh4PMSaDOM1y3cvUg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 EDD952820B78; Fri, 19 Apr 2024 13:25:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.8.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02C1F4EA71; Fri, 19 Apr 2024 13:25:16 +0000 (UTC) From: Wander Lairson Costa To: Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Matti Vaittinen , Greg Kroah-Hartman , Maxime Ripard , 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 v4 2/2] kunit: avoid memory leak on device register error Date: Fri, 19 Apr 2024 10:25:02 -0300 Message-ID: <20240419132504.9488-3-wander@redhat.com> In-Reply-To: <20240419132504.9488-1-wander@redhat.com> References: <20240419132504.9488-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: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 Content-Type: text/plain; charset="utf-8" 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_inter= nal(struct kunit *test, err =3D device_register(&kunit_dev->dev); if (err) { put_device(&kunit_dev->dev); + kfree(kunit_dev); return ERR_PTR(err); } =20 --=20 2.44.0