Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp286242ybi; Fri, 26 Jul 2019 09:40:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxboxoiPo4KLRC01A+JxWozwMjBfxiSdEcprNqBH77nDkswy1gpFa/7kV/xy8mETYbr9HtM X-Received: by 2002:a17:90a:9b08:: with SMTP id f8mr99674324pjp.103.1564159239057; Fri, 26 Jul 2019 09:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564159239; cv=none; d=google.com; s=arc-20160816; b=apyGCeha2I/QxQRm+alFfuY8aydgi56Wq/KcauOlUJxXZy2u8evYq4tUDudPxu9Zpg RhiWVqPoqXTcQbJQyYy3mVoS/tAa9Xz+ZuXBmXs0BRRhmCAnTcn6HPaRGni9O6AT3M4E dxXAElP/Y6XDo1lCUBCHCFgKW/PRR7jTIkXHjM2CJ7ubyGXW5bImaDKwHuJvN7s4s1/k NXCgbg7GGeUxpnsw/z+uh0Ocvxk37ftaqD/SK3RP/cybrq18nEz2XfoiDZFIvMTc33Z8 NT9MZLIV2dtuminm9lRfWEnVVDoxK6av7ZjVpJjpPmuh2jzA+zI/Hct9dZbrLWsl8R+M SHpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=IuTWU2vTMyRFMfL4PPCxvQbMigqNcvfYzq9U/ESsCao=; b=Na5KS4ScJMSB5T72rrtVWySwvJMk+uIpPNjEVW+pxXXdeiCHXz4TcO7a6eDOThI8in 9yDprnkzdxQYj4L8WPxGVBJ4xxNTy5+u+EmdNCFYGS8EVF/VsD+1+DHT/DlyoRPcJVCK Vi6iUTEC5eHv72P7GdQn7JucjXqpXHXLWbaZ7xY+zNNe34hNrJHWFsuJJQVauv+KCLNa CQCM2PMsfVCbg/pJpxhLQZ6UgPYpYwQ9h+TPrFssvlRplR1Zr9MzW+W2dOzMX1LPDDx4 BV+YXcdeMQi3bQMAuhi3UR23TX8HTRf0h9beSIYJkQFUekJ2wfufm7Rm9rmtJEJkgJPJ 8rlw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h186si21776933pge.110.2019.07.26.09.40.23; Fri, 26 Jul 2019 09:40:39 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388132AbfGZNnG (ORCPT + 99 others); Fri, 26 Jul 2019 09:43:06 -0400 Received: from olimex.com ([184.105.72.32]:41816 "EHLO olimex.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387632AbfGZNnE (ORCPT ); Fri, 26 Jul 2019 09:43:04 -0400 Received: from localhost.localdomain ([94.155.250.134]) by olimex.com with ESMTPSA (ECDHE-RSA-AES128-GCM-SHA256:TLSv1.2:Kx=ECDH:Au=RSA:Enc=AESGCM(128):Mac=AEAD) (SMTP-AUTH username stefan@olimex.com, mechanism PLAIN) for ; Fri, 26 Jul 2019 06:32:59 -0700 From: Stefan Mavrodiev To: Zhang Rui , Eduardo Valentin , Daniel Lezcano , linux-pm@vger.kernel.org (open list:THERMAL), linux-kernel@vger.kernel.org (open list) Cc: Stefan Mavrodiev Subject: [PATCH 1/1] thermal_hwmon: Sanitize thermal_zone type Date: Fri, 26 Jul 2019 16:32:36 +0300 Message-Id: <20190726133236.22872-1-stefan@olimex.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When calling thermal_add_hwmon_sysfs(), the device type is sanitized by replacing '-' with '_'. However tz->type remains unsanitized. Thus calling thermal_hwmon_lookup_by_type() returns no device. And if there is no device, thermal_remove_hwmon_sysfs() fails with "hwmon device lookup failed!". The result is unregisted hwmon devices in the sysfs. Fixes: 409ef0bacacf ("thermal_hwmon: Sanitize attribute name passed to hwmon") Signed-off-by: Stefan Mavrodiev --- drivers/thermal/thermal_hwmon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_hwmon.c b/drivers/thermal/thermal_hwmon.c index 40c69a533b24..dd5d8ee37928 100644 --- a/drivers/thermal/thermal_hwmon.c +++ b/drivers/thermal/thermal_hwmon.c @@ -87,13 +87,17 @@ static struct thermal_hwmon_device * thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz) { struct thermal_hwmon_device *hwmon; + char type[THERMAL_NAME_LENGTH]; mutex_lock(&thermal_hwmon_list_lock); - list_for_each_entry(hwmon, &thermal_hwmon_list, node) - if (!strcmp(hwmon->type, tz->type)) { + list_for_each_entry(hwmon, &thermal_hwmon_list, node) { + strcpy(type, tz->type); + strreplace(type, '-', '_'); + if (!strcmp(hwmon->type, type)) { mutex_unlock(&thermal_hwmon_list_lock); return hwmon; } + } mutex_unlock(&thermal_hwmon_list_lock); return NULL; -- 2.17.1