From patchwork Tue Nov 8 05:08:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 9416559 X-Patchwork-Delegate: rui.zhang@intel.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 204B760459 for ; Tue, 8 Nov 2016 05:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EA4E28B9B for ; Tue, 8 Nov 2016 05:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0294728B9D; Tue, 8 Nov 2016 05:22:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D6F328B9B for ; Tue, 8 Nov 2016 05:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752723AbcKHFWo (ORCPT ); Tue, 8 Nov 2016 00:22:44 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:32972 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752715AbcKHFWn (ORCPT ); Tue, 8 Nov 2016 00:22:43 -0500 Received: by mail-pf0-f193.google.com with SMTP id 144so9723951pfv.0; Mon, 07 Nov 2016 21:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5Eh55nhAbkQchp6cGLtEivyo8hTEe/Dx/BOPhzwibcg=; b=iW62xsNwvsr/WtuiWMHe5gUOnvm9Rnj1UpdEdDOiIVkwE5fYh8OA3GqlCEOkTGEUdE Bi1dk7DtW818bB234oIUZ6rMGkmTehIvtzH9KpWhWHC/jPvSnPZo7IDHFRBa/J7fs7mv I5wKR/EmJQduIiVAcJFxgM7sbanB4pfuTJQgtL005wLEgBtY0koX5+BgThffJFaNvnCV Vi5EzOi0Dl1nzyY+QVMuKSHRX117FiYZCSUvLwHGHvSf8yzVggKfN9DS3sNU2UbjGRd9 KMEdlim/0522OwK55ivJFf/6jWwwO/L1C8gaBMua6HcyJQCOgrwqwLD3fyQVGp3oFi4l yzXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5Eh55nhAbkQchp6cGLtEivyo8hTEe/Dx/BOPhzwibcg=; b=C1Sy8gUymS7WDrPleaCRCjqba88BhOmCv11hFi+SOdiBW/putaHY9puqqTvdyTuTMy 1zukaeJ2v4ShjfK2eEmAckmpGSw+6E/gJLS3lCINGXm/PVOHPm8mytFqDPg48912E71l lz66NGxKxTiyqmTUQbjUZT3ykZgoG8kxjiG7aIEAnwKC7GcqTRGmSLiU8SBR2DxTE+yR fArQtoc05Z85St2j2oPzvIazBEqX5yxcMNZVQBVCGYprwPcHk/wFcjYkRgQJiVeYZprk 0FLHvfJj6/PE6wLLMDCT1w9KgUujK5vRq3mlmoVeQ6PZmUgrb8GOZ86PkF2Qm7wy7ynC ramw== X-Gm-Message-State: ABUngvdclJHjzIiu+N46dRQBh0mfsmLl0NIiN43eWF+XyX2tpnyQEy8ZqV2w8HeWExKytw== X-Received: by 10.99.2.142 with SMTP id 136mr16132845pgc.25.1478581775257; Mon, 07 Nov 2016 21:09:35 -0800 (PST) Received: from localhost ([2601:647:4401:a2f0:7256:81ff:febd:926d]) by smtp.gmail.com with ESMTPSA id n17sm14905660pfg.80.2016.11.07.21.09.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:09:34 -0800 (PST) From: Eduardo Valentin To: Rui Zhang Cc: LKML , Linux PM , Eduardo Valentin Subject: [PATCHv2 01/49] thermal: core: prevent zones with no types to be registered Date: Mon, 7 Nov 2016 21:08:39 -0800 Message-Id: <1478581767-7009-2-git-send-email-edubezval@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1478581767-7009-1-git-send-email-edubezval@gmail.com> References: <1478581767-7009-1-git-send-email-edubezval@gmail.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are APIs that rely on tz->type. This patch prevent thermal zones without it to be registered. Cc: Zhang Rui Cc: linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_core.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 226b0b4ac..ec0d158 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1873,6 +1873,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, int passive = 0; struct thermal_governor *governor; + if (!type || strlen(type) == 0) + return ERR_PTR(-EINVAL); + if (type && strlen(type) >= THERMAL_NAME_LENGTH) return ERR_PTR(-EINVAL); @@ -1898,7 +1901,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, return ERR_PTR(result); } - strlcpy(tz->type, type ? : "", sizeof(tz->type)); + strlcpy(tz->type, type, sizeof(tz->type)); tz->ops = ops; tz->tzp = tzp; tz->device.class = &thermal_class; @@ -1918,11 +1921,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, } /* sys I/F */ - if (type) { - result = device_create_file(&tz->device, &dev_attr_type); - if (result) - goto unregister; - } + result = device_create_file(&tz->device, &dev_attr_type); + if (result) + goto unregister; result = device_create_file(&tz->device, &dev_attr_temp); if (result) @@ -2071,8 +2072,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz) thermal_zone_device_set_polling(tz, 0); - if (tz->type[0]) - device_remove_file(&tz->device, &dev_attr_type); + device_remove_file(&tz->device, &dev_attr_type); device_remove_file(&tz->device, &dev_attr_temp); if (tz->ops->get_mode) device_remove_file(&tz->device, &dev_attr_mode);