Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4365633ybl; Mon, 9 Dec 2019 09:35:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxgIOrnOGUw6rZjqxCakPpqVThnDGz1YJgoBeCWofKCyYsA8hb8qiUtnnT7vyeQ+Zmv8c4l X-Received: by 2002:aca:4f50:: with SMTP id d77mr124818oib.147.1575912945126; Mon, 09 Dec 2019 09:35:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575912945; cv=none; d=google.com; s=arc-20160816; b=VepiZ864wxy8kD6ZA90XksM1b9lm6pf92Je9Fr6MfV+bXQ+SZbNL8GKb9ngTpIIt7r bCkppZhsTufXrcB63WIS6obmcG3u1BJZ4rvO04dqdOnHpW1uV4Y+b85qeKKsZBBRd7sz tD37VaZH9lniI0nVh2BylvX9q6Q3i7L2979OiCkeO0O6ZBrHlVtKyovMqex2s2qMPCGd xQRmi7Qb2Cx9oHaL+tN4AO3vWZXZpvHAxmp3v0gLHMgSOdyyLvVJxDVn8+AivtOZrZX2 3UBrez7EpTaBBn1Gaej5iPlop1Wi2wibGvWR/ThnvabX4hMOBmXd23VcqxiEpQ5MplG/ Jp+w== 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=MqGWgekCxDubwDbyQN/6yZHuFRZ1dg3jUzpNTfM9+xY=; b=bew0SVsEzgGz3sqai6P1QKm/gfX6oDoWgqfaQoS1gi6tTA/yHwerz9w4cMJtBbqmeT XJvJbVVWYnVqGUPaYU9CJ8LwOWFylL23Yi9j/g3UVSnea1xPrUvWsJ42/Pn/0uso8oH1 4+cm+m5e529yuxdSmB1DByky7lnCKE0KtbdNClF/Dq4wPb7p5yPhF/nuoRdiCuFfreFx utmgJIdQOK8YVysuYvhDXC4H8nifPKIxIB9TPRffUJPgEslUh2mEEo7orcrJ1k5LbCc+ HiG6NqkaHnphmI6qZclWd2rW1tvPePkjZF/Ts7WQVKBbaefcFPG/385X4qO9HoGd0YLx 2Ueg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gQTZrrf4; 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 d23si195439oij.270.2019.12.09.09.35.32; Mon, 09 Dec 2019 09:35:45 -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=gQTZrrf4; 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 S1726538AbfLIRep (ORCPT + 99 others); Mon, 9 Dec 2019 12:34:45 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:36681 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbfLIRep (ORCPT ); Mon, 9 Dec 2019 12:34:45 -0500 Received: by mail-ed1-f67.google.com with SMTP id j17so13425734edp.3 for ; Mon, 09 Dec 2019 09:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MqGWgekCxDubwDbyQN/6yZHuFRZ1dg3jUzpNTfM9+xY=; b=gQTZrrf4vN8IBztt71aOzBZf8fdXSZ0eVtga7ZrfIAjwHB+D4J+M5Gc6L1lqW8B1ed 2hCTiPcUFtkv1eE5pJ8WY5g1/EQiv133HBNom2s1cRHxGXsQzapUnWhENnTMW88DS0V0 X+MOu2GLoqpNrLhY1i9kD/6WjHXWDUd8rL4Okz0SphkUCDd3igh/0rzDdH9xY6iggk97 n/J4eEH161Cj05AB/ESQ2pCmsWfJ3Or66VZdoF6TJJXvpqjWGTkobDE7Z+WOwP/P33vo 1/r0SEQ509ttPWpW6Ir9mHvPzwSGe+e9bwI+Xks5GVVqRrLSU/BcZlXHZ9zeFuYKsGKH sbRQ== 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=MqGWgekCxDubwDbyQN/6yZHuFRZ1dg3jUzpNTfM9+xY=; b=Z+6S2JUU9Lrw+2eDHOwAfW4L7oA/lyGcnvmhBNKs4E8h6blc79nL2yG8+/pkFQs5wq xhXSCfc3jk+Xms6aVwuJvvdZjFJheeRu4oz+76BCNQ+QE8632rskMHyYyRpXaMbHPNmF jI24Zm1/2i96R0ap0wKj9tckVHgPK2QBeKxIQrtFHwDeMsmEOoE72u/1GBBuGQz0edi3 awzYJqqZJQxm1kyw9h2TESfRNqmSWAgZ8yCrpRT3nUL+VnG/ip5WRwd3RImG7XFze8Rw MWSHL12glD6QGpk8WIntxJEStQcQDssAd6fSd98hR+qsHEge/QT7BoygGCbOyzT77Qlx QGbg== X-Gm-Message-State: APjAAAWo8S3Um4Tu2s5XcOrzCH648mmSvIW8zLo3Sq7Myy/GBRf5Zd5s nGIpHcDo8E/kkVUejyrvzm71hpXQm+xNeelLlb8uPg== X-Received: by 2002:a17:906:4881:: with SMTP id v1mr9011744ejq.329.1575912882849; Mon, 09 Dec 2019 09:34:42 -0800 (PST) MIME-Version: 1.0 References: <20191205071953.121511-1-wvw@google.com> <20191205071953.121511-2-wvw@google.com> In-Reply-To: From: Wei Wang Date: Mon, 9 Dec 2019 09:34:31 -0800 Message-ID: Subject: Re: [PATCH v3 1/3] thermal: prevent cooling device with no type to be registered To: Amit Kucheria 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 Sun, Dec 8, 2019 at 11:41 PM Amit Kucheria wrote: > > 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. > Thanks Amit for the review and testing. > 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 > >