Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2397152yba; Fri, 17 May 2019 16:34:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqegVklXVFpyWb2YYyS2/x59JEqJtd1fuih5YMOAyEziPLAe+ogmz6Bv7hTJI+zzl39E8P X-Received: by 2002:a63:4006:: with SMTP id n6mr60233428pga.424.1558136052827; Fri, 17 May 2019 16:34:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558136052; cv=none; d=google.com; s=arc-20160816; b=G8Ek0Nh81OIcpUTYn3lTlxhuiDDupctGT5efZu7yWJ+HYargRUFZEEE39HvJwfMoLF mfP1dB5PaLTJZT2tqIxd1IPlgUFhmrs+AUy8MRwj/hm89IGIqwvf2lV1IUB74jnPlOLr osXrCB8X4Oa6cEdr/L9j0eSJdeg9fawHiySkBF/V9A0S/qjtAj+OFBoONw0PsrWzMk9n yUb7GPt1H7A52tlp0NjZ+ZoVfhe4t6qBJhHWEpg+bTLbaUa67eLJUk2LT+12NHuUdMGL gRu1P5oTuENZtBrNdUNT4OOd8z9MwYWo8OF6OQn5xNF+matO96zj0OeJ7GoqVHmQMP4S GthA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YzwMlzH7xToQwqdmfuxN3FjSxsAuK3aol4/PCCQcBXk=; b=d7syKIc4Tfe6Q3idD/dmX2LYZQNpa22CM2JQZ+o8MVuLjL1uNn+Ke0DkCZYsrD8azI c8NIWtUBX6VGB5OQ38fvvwjIOCT/1QQQWf4uXYtf7ltv9ycfukcgqN3aVCTj7M9wVxtl KlL6SE3MgQZMRUAMSPz95xFX1+igRQq0Z93KROxftUUk7nkU91PVYP5uCaMunixkfUzn 9pjOPljXZewxccIQWhck6GYGYie1bPD4ie0oLoaD1q4sorZLFVLPNllhr6pGXk7jBJRX jLa2W7iJ8LLa/7iIRv3URuKPf8uaG5ir+7l0R2ZdtV0568kEbVmY+rF13XcWUtxU6Tum M4Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Lb04dCqI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 66si2120242pge.462.2019.05.17.16.33.56; Fri, 17 May 2019 16:34:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=Lb04dCqI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728925AbfEQXNq (ORCPT + 99 others); Fri, 17 May 2019 19:13:46 -0400 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:36207 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbfEQXNp (ORCPT ); Fri, 17 May 2019 19:13:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1558134825; x=1589670825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YzwMlzH7xToQwqdmfuxN3FjSxsAuK3aol4/PCCQcBXk=; b=Lb04dCqIPQ2XCIFL103wRVliTHFoFhqm2MG8zcdrDdkxfdEt3zP5+pGG lM7VMmVUC15ltWjeQxbpl5wxDzoujTa9LTGrqNqAkPZPJQA+wSokNED7f qJTXf6Wo+HSsfPFv23k62SWOIJMDDaELCe9qV/L/riarlL7G01O3XPrfS c=; X-IronPort-AV: E=Sophos;i="5.60,481,1549929600"; d="scan'208";a="805299185" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1d-f273de60.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 May 2019 23:13:42 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-f273de60.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x4HNDWrr055781 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Fri, 17 May 2019 23:13:41 GMT Received: from EX13D05UWB001.ant.amazon.com (10.43.161.181) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 17 May 2019 23:13:40 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D05UWB001.ant.amazon.com (10.43.161.181) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 17 May 2019 23:13:40 +0000 Received: from localhost (10.94.216.44) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 17 May 2019 23:13:40 +0000 From: Eduardo Valentin To: Guenter Roeck CC: Eduardo Valentin , Jean Delvare , , Subject: [PATCH 2/2] hwmon: core: fix potential memory leak in *hwmon_device_register* Date: Fri, 17 May 2019 16:13:37 -0700 Message-ID: <20190517231337.27859-3-eduval@amazon.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190517231337.27859-1-eduval@amazon.com> References: <20190517231337.27859-1-eduval@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When registering a hwmon device with HWMON_C_REGISTER_TZ flag in place, the hwmon subsystem will attempt to register the device also with the thermal subsystem. When the of-thermal registration fails, __hwmon_device_register jumps to ida_remove, leaving the locally allocated hwdev pointer and also the hdev registered. This patch fixes both issues by jumping to a new label that will first unregister hdev and the fall into the kfree of hwdev to finally remove the idas and propagate the error code. Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/hwmon/hwmon.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c index 6b3559f58b67..6f1194952189 100644 --- a/drivers/hwmon/hwmon.c +++ b/drivers/hwmon/hwmon.c @@ -637,7 +637,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, hwdev, j); if (err) { device_unregister(hdev); - goto ida_remove; + goto device_unregister; } } } @@ -646,6 +646,8 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, return hdev; +device_unregister: + device_unregister(hdev); free_hwmon: kfree(hwdev); ida_remove: -- 2.21.0