Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp952838ybl; Wed, 4 Dec 2019 13:57:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyLJ0486x+M1s/ojNjq4lkSLKj2PulCbEehk7joHbxUYb60PvjWkS3lbVADys72Qc0H4fxI X-Received: by 2002:a9d:7dc9:: with SMTP id k9mr4298128otn.117.1575496647137; Wed, 04 Dec 2019 13:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575496647; cv=none; d=google.com; s=arc-20160816; b=0UOuitWv+wQMaufZ10FJfNIAhKmQJ7mz2xd5+Bg3jVO0LsAn6tWPx1t4pU06Xg2whV BSEgyQl3H6dNSZfvmAs3Hsj7wXGaXilPFQbD6bMxCsB+jrPeY8xAIr1iWDFuFfXkNejq Ci3LDvCSdc+EktD9EHG3bmSFrFmWbexj93uB5LzfhgKuWOVrsgnXfe7HofgKre/qTR+G FJswJqlGOtMn8zyjiSapQ3FtGrpuVdgi7TKcZc9d24bZbzo/qqXyWIiNAOnhCo3cBgIe bSnla4XI1q/CM+QD0nDCpxAFRkICttrnus9VzK5ILVT9JMDRmkIf/8cIGZJIBhO8S1VK xBjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:cc:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=NAupc/vR8bVWuaMCvX72N/qStHFA90T0ir1IJdUyDdE=; b=nW1+NoypsJHDAqGTIWQ2N3JZ3gMJB07eCbyMuooP5WJ7wDpB6a2n7o+vaU/KD/+6ja F3JcDFr5vtaXevq8T7pSUfqXl7zYgnOGTOgKF8gDlnY2l0OXbCaOVFpRSKQjri2oUeIB EuRU6BEHQVkbQQ7o4vj7lFdWM+EqIIEKJmj8XI94rqWZTuGP9wYE8pMQjsJ0/wBgWscl PL/XXsf44lIhM/dhQ6/uL7p6i3kNUDe7NofGC1OCZgaEB0tzmTxNVl9Bw4fny2Ht4cNH a8OoRi7peHHFjW+8htZ4VSiTPpxE6B/hWS8jAWYJnJkH6Aj/JvIr1vP1U7y6ba4r3rBS hfgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="sbU0t/Kz"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si4388878otb.140.2019.12.04.13.57.14; Wed, 04 Dec 2019 13:57:27 -0800 (PST) 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=@google.com header.s=20161025 header.b="sbU0t/Kz"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728347AbfLDV43 (ORCPT + 99 others); Wed, 4 Dec 2019 16:56:29 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:49625 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728321AbfLDV42 (ORCPT ); Wed, 4 Dec 2019 16:56:28 -0500 Received: by mail-pg1-f202.google.com with SMTP id u14so538649pgq.16 for ; Wed, 04 Dec 2019 13:56:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:cc; bh=NAupc/vR8bVWuaMCvX72N/qStHFA90T0ir1IJdUyDdE=; b=sbU0t/KzGn2j9p0ayPj+KQNR/KUydw26BP24k17+yr+P4OCHLehU0UBTL/B2Abr+/2 sQf5fD9mTwnZooHzWk0YZlJXAWEb6f/7Dl2oRN90wghJoWjU1+h309N4d0U4PBHtycjQ UXk+UrCUxUqY9RTQNkYfFeqxqIS46oUAo4BZbnFiVoP6yJjiTBK1PFEPvuICfFtbrpss mdU+l9/cNMdnFQ3do4so/sm9xyh7Z+MNh4eU0a+QhACZ9wCqQ4mjLA9ZOIS+Dgu3D23W rNyRmVb3lUx1so88I8VXF4i54g1OA8QcfKt3BkPTiikWozM40GsdcSzXZP5zA7q/4jTL XD0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:cc; bh=NAupc/vR8bVWuaMCvX72N/qStHFA90T0ir1IJdUyDdE=; b=UOFKSAv99aRAsDvqbe9mnVQx65g2UKqr1u0SBbjDVb2aBRKRq7Ko5GuDU2vQH1lfvf Ok53GJVnZxbb2W9v4aT50eBs9c0LAcX14C4gognzonLUGIcEM0gHK4VKDt/m7M6VCzxy cKChFL2axUQTTwid6UafOeRRw+ZiDEylTSnXTQmDBHglpDca96OD3I7dLeZnuLH4BCUC AOD4xigU6kT9jhq7G1fHDj4QCwet5N1u/kn6GabBDXpHAHGdSTaVNur5Aan6EBao3gEL fbUTfs1+cRI4TEoXyINbIxz6OYV4rMdMBLiXsgR4vqcm53Siu5GVrPxawjSqrCOx2VQR gkMg== X-Gm-Message-State: APjAAAWjxrdA9ARlPL+151i0Tpwl29LwzJbTymYE3a4EDE8rDvLZ0290 5suOfAW8AaUpeLHIU/AdnurkEH4= X-Received: by 2002:a63:2cc9:: with SMTP id s192mr5708130pgs.396.1575496587829; Wed, 04 Dec 2019 13:56:27 -0800 (PST) Date: Wed, 4 Dec 2019 13:56:17 -0800 In-Reply-To: <20191204215618.125826-1-wvw@google.com> Message-Id: <20191204215618.125826-2-wvw@google.com> Mime-Version: 1.0 References: <20191204215618.125826-1-wvw@google.com> X-Mailer: git-send-email 2.24.0.393.g34dc348eaf-goog Subject: [PATCH v2 1/2] thermal: fix and clean up tz and cdev registration From: Wei Wang Cc: wei.vince.wang@gmail.com, Wei Wang , Zhang Rui , Eduardo Valentin , Daniel Lezcano , Amit Kucheria , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make cooling device registration behavior consistent with thermal zone. This patch also cleans up a unnecessary nullptr check. Signed-off-by: Wei Wang --- drivers/thermal/thermal_core.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index d4481cc8958f..64fbb59c2f44 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -954,8 +954,16 @@ __thermal_cooling_device_register(struct device_node *np, struct thermal_zone_device *pos = NULL; int result; - if (type && strlen(type) >= THERMAL_NAME_LENGTH) - return ERR_PTR(-EINVAL); + if (!type || !type[0]) { + pr_err("Error: No cooling device type defined\n"); + return ERR_PTR(-EINVAL); + } + + if (strlen(type) >= THERMAL_NAME_LENGTH) { + pr_err("Error: Cooling device name (%s) too long, " + "should be under %d chars\n", type, THERMAL_NAME_LENGTH); + return ERR_PTR(-EINVAL); + } if (!ops || !ops->get_max_state || !ops->get_cur_state || !ops->set_cur_state) @@ -972,7 +980,7 @@ __thermal_cooling_device_register(struct device_node *np, } cdev->id = result; - strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); + strlcpy(cdev->type, type, sizeof(cdev->type)); mutex_init(&cdev->lock); INIT_LIST_HEAD(&cdev->thermal_instances); cdev->np = np; @@ -1250,7 +1258,7 @@ thermal_zone_device_register(const char *type, int trips, int mask, return ERR_PTR(-EINVAL); } - if (type && strlen(type) >= THERMAL_NAME_LENGTH) { + if (strlen(type) >= THERMAL_NAME_LENGTH) { pr_err("Error: Thermal zone name (%s) too long, should be under %d chars\n", type, THERMAL_NAME_LENGTH); return ERR_PTR(-EINVAL); -- 2.24.0.393.g34dc348eaf-goog