From patchwork Thu Dec 14 10:52:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 178646 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8453729dys; Thu, 14 Dec 2023 02:52:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2jZb2rsbzyL9B1H7S52aDjLbNSiiMu7g23Dg0jQrXO63U1I/WLe46vMvl/rHHtCmg1grN X-Received: by 2002:a05:6e02:1a4d:b0:35d:59a2:bbc with SMTP id u13-20020a056e021a4d00b0035d59a20bbcmr8466734ilv.82.1702551160306; Thu, 14 Dec 2023 02:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702551160; cv=none; d=google.com; s=arc-20160816; b=wAw4i7KytqA6sz67WA89Lj3a+t5mw2vhH1NgAtMgDJwK0jVjNDPBdP6VKoaGlWlh82 FOlseJwVpXNcdji7dUseI23rHrzX5OHA5bmm4B7XieKVyZichFrUbRJGS0/k8XLuZvEp RiFTvvPrX+67x078NVhVNfmSCvVAj1sfPTo99zC7SZnsEVGOqhyJLmrXR4J1kbVvHJOw CCyc4Qpx4TrWsvkYPBYvpMaJdKUbtI8eqSWJm826ff/dFOnmRDHsGWPNHRnjJ4x08O6s VeSTSK5LscaKP+pjiookNRgI28ZLomSy4Gbee4V/xYl7KfTssOWKX1yR6M8YpgdN4m/u zUfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=CQV8JjfxQ+sGZGn6RtAsk9JhwP9Dl2LijMaXH8ztClc=; fh=0LAKsbFkCSQWfu1i8y+7iTZd2YfKgOu80rNU4A+KQM0=; b=ixdgNQ0SmiCY++CcXj4PhbsCZ4t1eLXwAy3t5xk+VzK9zj0bWT3tXzE4oB9BRkz2+h hIilR8UI9OXC8uruO93nl1QL5nvD6gh6E2YhRawNTOByKHt/jUmrwxPT5hezVgNs3klL hM7KHs5It6QawaUxuQvgTmVX44zn/hxJFlpJJj6FjUkSazIGJzUFrISdMl7KNnnrpPj0 2/CgGtNr/n+TG+B1s0eVAtKqBGcI2knBlYo2z2HngZDM9LXLo2YCSidobKC+5BkakTUK GUQFu5PTN1NdWPgtgGViK5oelwM6vMbldm7wo8ZRLkg/N0KdMvpPXw7qw4C2qumHEl7K tBiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id p20-20020a63fe14000000b0059d48c43152si11214219pgh.40.2023.12.14.02.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 02:52:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 60D0D8026A75; Thu, 14 Dec 2023 02:52:33 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443745AbjLNKwY (ORCPT + 99 others); Thu, 14 Dec 2023 05:52:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443734AbjLNKwX (ORCPT ); Thu, 14 Dec 2023 05:52:23 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 858C9BD; Thu, 14 Dec 2023 02:52:28 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.4.0) id b379b9c677731927; Thu, 14 Dec 2023 11:52:26 +0100 Received: from kreacher.localnet (unknown [195.136.19.94]) (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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 0EEE86689E6; Thu, 14 Dec 2023 11:52:26 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM , Daniel Lezcano Cc: Srinivas Pandruvada , Zhang Rui , Linux ACPI , LKML , Lukasz Luba , Dan Carpenter Subject: [PATCH v1] thermal: core: Fix NULL pointer dereference in zone registration error path Date: Thu, 14 Dec 2023 11:52:25 +0100 Message-ID: <5737641.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrudelledgvddtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepffffffekgfehheffleetieevfeefvefhleetjedvvdeijeejledvieehueevueffnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthht oheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Dec 2023 02:52:33 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785254285112898194 X-GMAIL-MSGID: 1785254285112898194 From: Rafael J. Wysocki If device_register() in thermal_zone_device_register_with_trips() returns an error, the tz variable is set to NULL and subsequently dereferenced in kfree(tz->tzp). Commit adc8749b150c ("thermal/drivers/core: Use put_device() if device_register() fails") added the tz = NULL assignment in question to avoid a possible double-free after dropping the reference to the zone device. However, after commit 4649620d9404 ("thermal: core: Make thermal_zone_device_unregister() return after freeing the zone"), that assignment has become redundant, because dropping the reference to the zone device does not cause the zone object to be freed any more. Drop it to address the NULL pointer dereference. Fixes: 3d439b1a2ad3 ("thermal/core: Alloc-copy-free the thermal zone parameters structure") Signed-off-by: Rafael J. Wysocki Reviewed-by: Lukasz Luba --- drivers/thermal/thermal_core.c | 1 - 1 file changed, 1 deletion(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1394,7 +1394,6 @@ unregister: device_del(&tz->device); release_device: put_device(&tz->device); - tz = NULL; remove_id: ida_free(&thermal_tz_ida, id); free_tzp: