Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp638195lqt; Fri, 19 Apr 2024 06:25:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW7MAipmaI3Rw5utsb/JIieomZId2a8W82D2mJIp5tONw2MZHNqxSrVjH/4gUBMeK/ZVIMzlksymZPWa0N4Rcgx6k9q9wcBt+uUiMm5Zw== X-Google-Smtp-Source: AGHT+IEFtDC73PijW0JLkjK/r871A/YQvFBAFWaFU9CejCjJ/gXgSdbzmFVfGzAO+kCtEQi0BGek X-Received: by 2002:a19:f50e:0:b0:518:6f50:92eb with SMTP id j14-20020a19f50e000000b005186f5092ebmr1392370lfb.46.1713533146204; Fri, 19 Apr 2024 06:25:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713533146; cv=pass; d=google.com; s=arc-20160816; b=QWVJ98sAEW9aORuM61qPqwGiyTbdncuciGq1C+9o/6sWCqZe7MgQEewCKgaz3digpj HJCvn5d4j39xeqp4kv0Qm0/ZkKYxIqq2NKlwle7gVf1M0/e9s9E64FUY1zO//dLjQkSN akE1DqGFqelRtDNLzUdYjzR6//Lg3ZUp0wZUACNbMpmBzfav/j08wnVK8tpP030Cm6nP gjVvInO3yjvgOKQyoMSu9L7WSLSHn47QAnM/f7+q+0ECB23VQGTMvfCzwNVpNWw56UMO QldzHd8H9Zk1vpFTgsDDDR1PLK5iEzbycqTH3BBGwvYPPqreIxb71fOVPDmGnYVJS8rG tqcQ== 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=QKFWmD89ZfxI3WrGZY3k5MGYxU+9FObI37ylz+l21us=; fh=V49MSgbkUJWF/ZQeH9v7YpsFy7ApETLnZVJ52uK/KcY=; b=HgDXKQrFk6PPjyidrhJ3kAphrKALHr5n68Y2qD1NFhxFsHd1usyKBK1GQqWsoMitCk oqrRbW6/QCRxFWLOkgzn1TK1Nlba7ouwDMXg/YWRNt2fVAr7E1Xk3e39NUOhRPPQxYdC KytDYspis/HWVshIZXGpr/xRTC5k2zK+Jpx1+DGwzn9/DOa1376XA2+wqBNu2R5Mv0ws 2MaIbEXq6MTM4UWzREAuKB0WCBVIqvQ1mhIF6okGAyBcws6FGUWpboaEofJ1R/s6Tn41 dKejCuzT/Z9ZK0wqMR6XwO1QAuNQt6RB3i7PYbLgA+k7FmGcFggi4nIpizcNC+BropW1 LMBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=F4ok1DKx; 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-151467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151467-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 o15-20020a17090637cf00b00a4a3d0e7464si2154134ejc.357.2024.04.19.06.25.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 06:25:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151467-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=F4ok1DKx; 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-151467-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151467-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 C58971F23109 for ; Fri, 19 Apr 2024 13:25:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0257F12A14E; Fri, 19 Apr 2024 13:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="F4ok1DKx" 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 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: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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); return ERR_PTR(err); } -- 2.44.0