Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3803991ybl; Sun, 8 Dec 2019 23:51:11 -0800 (PST) X-Google-Smtp-Source: APXvYqycxx9oBLTLbBGHedO+IoXJZ+gpI7c/vfG3Op6vrRY8X7vXU07u7/WVXe8dLOBGvMyOhGsi X-Received: by 2002:a05:6830:1707:: with SMTP id 7mr21620843otk.185.1575877871228; Sun, 08 Dec 2019 23:51:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575877871; cv=none; d=google.com; s=arc-20160816; b=Jb0O5GQh2elH2GsGBOO89cF02Heu5j/L9JVOPd0orHH8yc78hOY4vASh01dHKBjCgV ZalsPfSEGcCvFJyZr4nnxXnAL9HsW/CGa8x60a7NxLMTfNh8hs66r69G2AywyAhapwh6 lm06NtvtuELpav+UDShPvYqpatyQr//XvBR9eGs/U3wj9y94NI38Or7CBjz1DKTGWme4 xJtflXTNzwpn4BMm+xXTt1YKyf6W/4bCwUp/Mp9og1d6JYDCiRAfN0yHRzyhqsrEvc5S eYvSMkTW0qz6Hg3gtNw2bQfkLSU9RkSHJpGPJtz8KfDAfQBlfIxSY4qXHsPQlH44SsiE tmEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=H1QDiAgOowx6HRyiT2osPzP0rSI4d5md9+jwOOejkvo=; b=GG+rauBaMZKcGJUlvLPXnkr9RVy8WpyPeC8iWWLNOcodb9B9FhdHMJOlTjwgGydeJ/ t2incZTMJRE1xOo8jbQz6hVplLA0GIB7jdK8+QERKr1nvDMQIU/Z9TApA3Ril4idml8+ 2hPLBHotvJBbsKPqqAv44/s3z2IkVphkYGLG5+2CxVQX5Dc7jFH0uIVofQunaMsT8M3B NWzrO/ShXAnjQdidL7f3tFfzfBu+cnf3H21hF4+jEu6FKYhlEIJb49es+jhI6xAir1Wx d4I6ICL+Q+XEQlzgmvQzjb6Dy0c9BrOjSaoENCA3LJWXOXlj6bBPtsjrZZVt+GY0XJlo qyBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=s3NVtX6k; 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 k2si2530789otp.273.2019.12.08.23.50.58; Sun, 08 Dec 2019 23:51:11 -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=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b=s3NVtX6k; 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 S1727187AbfLIHli (ORCPT + 99 others); Mon, 9 Dec 2019 02:41:38 -0500 Received: from mail-vs1-f66.google.com ([209.85.217.66]:46508 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726623AbfLIHli (ORCPT ); Mon, 9 Dec 2019 02:41:38 -0500 Received: by mail-vs1-f66.google.com with SMTP id t12so9539335vso.13 for ; Sun, 08 Dec 2019 23:41:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdurent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=H1QDiAgOowx6HRyiT2osPzP0rSI4d5md9+jwOOejkvo=; b=s3NVtX6kURu+PyFwZMjFwGZvHoOwdPqDkgt0r0Uc5eqwM0wbNWEESnBAcYCC4l6kna konqXC9ZYUJhy+JR29mQt/RS88y601JmxFoSKsze7iPPaYQOiYM6YbJZFT8GE7rmxcg1 GI7UHSwsjb0grFRxZqTcIQZlVclJkH6Pk15vseUp0Gcm2J0JKu9Fa9/RjC0kpBsvtUVa 55mnDVTjUDUUab6Q8MTuBRny9/dGFld948mz7ql5/DlJbJzNs8Yx0A5sQ32UnDrRn2Wb giNdPEZjoCxsfQUInranwDbvx9L5huQCSaCAoJfJqCTXz5uEB0oEOdVgaFzi3kBel0eC oL/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H1QDiAgOowx6HRyiT2osPzP0rSI4d5md9+jwOOejkvo=; b=FHP9n/u/TWeQmc/mopDRPLA6gx9po5/u2I2o9qbgS8YMZ2RQA1t0sbU7h35y8dVVT3 v3P4ivkQIyBKcHbMY3m5qfSunpXrD8sqQqo8CNGOGmsPaycruYEbPF4WRbKeXFBqwxkS d+gMch33c2f6pPcNVfQeUzmmAIhmCGzbgK9SvZrOzM3LgrU+UmeN+zGr8c5So8L2BM1H rFdONeNj9411cPDxfrTfhaaXP8eNr6hQiIkjhS8ezk6dbJsUPTQywnzkmJftoA5v1AkP fn5T7yfhaMuIRecx3tHF/7uoVk86o0QVqVbz7gwOjlxN7vFnnni+ESh2DN778lBwB4EU w26g== X-Gm-Message-State: APjAAAVtlKAp9Zg9KPLqjZuE4tDkY2/TFWPMd78INTzzQD0SWlUHKWon J1A7fpfIbSfwMNm+bswvE9ucpS47SxOQMPyg0y8f4Q== X-Received: by 2002:a67:f496:: with SMTP id o22mr18951450vsn.9.1575877296642; Sun, 08 Dec 2019 23:41:36 -0800 (PST) MIME-Version: 1.0 References: <20191205071953.121511-1-wvw@google.com> <20191205071953.121511-2-wvw@google.com> In-Reply-To: <20191205071953.121511-2-wvw@google.com> From: Amit Kucheria Date: Mon, 9 Dec 2019 13:11:25 +0530 Message-ID: Subject: Re: [PATCH v3 1/3] thermal: prevent cooling device with no type to be registered To: Wei Wang Cc: Wei Wang , Zhang Rui , Eduardo Valentin , Daniel Lezcano , Linux PM list , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 5, 2019 at 12:50 PM Wei Wang wrote: > > commit 54fa38cc2eda ("thermal: core: prevent zones with no types to be > registered") added logic to prevent thermal zone with empty type to be > registered. Similarly, there are APIs that rely on cdev->type. > This patch prevents cooling device without valid type to be registered. > > Signed-off-by: Wei Wang Looks better now. Thanks. Reviewed-by: Amit Kucheria Tested-by: Amit Kucheria > --- > drivers/thermal/thermal_core.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index d4481cc8958f..974e2d91c30b 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -954,12 +954,22 @@ __thermal_cooling_device_register(struct device_node *np, > struct thermal_zone_device *pos = NULL; > int result; > > - if (type && strlen(type) >= THERMAL_NAME_LENGTH) > + 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 over %d chars: %s\n", > + THERMAL_NAME_LENGTH, type); > + return ERR_PTR(-EINVAL); > + } > > if (!ops || !ops->get_max_state || !ops->get_cur_state || > - !ops->set_cur_state) > + !ops->set_cur_state) { > + pr_err("Error: Cooling device missing callbacks: %s\n", type); > return ERR_PTR(-EINVAL); > + } > > cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); > if (!cdev) > @@ -972,7 +982,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; > -- > 2.24.0.393.g34dc348eaf-goog >