Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4578289ybl; Mon, 9 Dec 2019 13:15:53 -0800 (PST) X-Google-Smtp-Source: APXvYqy99qRfCoKfj9m3j0KauIPxUNn2nVAJ49iYhnNB5I7D2WdkLrih2amEwyBCqNJHXWu0ZUgy X-Received: by 2002:a05:6808:24e:: with SMTP id m14mr1057253oie.168.1575926153649; Mon, 09 Dec 2019 13:15:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575926153; cv=none; d=google.com; s=arc-20160816; b=Mm1mWD8nTsBd4trWkdnY4HQ7sgcRR19L/JXtYmqZ6NNGW8XcSgPsrC/zyU9uTGZ5oH WoCYimlm3G/RkNwSRKVWu3YCThgsFRvFsznVUBOfi6E4JyxgtgdT2B6yaB7Sd3YWQR0i xVD0/ebJVU/7rzg94m5oy0PjGCucdFp4V8VMyTK4u6FRZWqFI08X6nQivNDSNQubN6pQ jLzG2J/L7u9ZE09SWRuztgmmbUM6PfQZQVd7LGCsaMtg20S9SbYkHt1U8kKaIBFXAN6N 2l5rVmAhdy5Vq75JK623aRDsnV3lwmnuykduO2AQENQftlMc9uSRZN7nUIrKMJWZ47kn 6izw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=3ZAoOzsHYMKfDXOLJj5uoHSZwKX72h4MMlTI4huTal4=; b=kZwzlVK/vq0hu/t+/7dTTHh3LWazQ+KAH2LS+Pn9Fs85no6mBsU25kSxCFzvSULYWb rN+Wh+lM0T59VzLq2MA+XjgA6F91h6AKTlCSKZK68psVPG28DkG1KfItlbv4icnvOKAN Pb6uBCiPZxwy+M4CP3DEWJWQW6OvHQrVBOYvru50fYUZ92eujW9QJ+HexIoY63XmfOao cWlwq1NT7xZN3j4LPkm/riN9LPYsUgRxc92W1Ir8N7SsEIzv4PqiMo6iV0X7A380FzVD k47HKnJebO+L+2eegyzu49FQZjTcgX/RMgKMCMxtCPOWgMV9a3aZMAShAUnl58XqVCRf vVLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W6mljHLu; 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 l17si626705otn.220.2019.12.09.13.15.41; Mon, 09 Dec 2019 13:15:53 -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=W6mljHLu; 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 S1726665AbfLIVNr (ORCPT + 99 others); Mon, 9 Dec 2019 16:13:47 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:40991 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbfLIVNr (ORCPT ); Mon, 9 Dec 2019 16:13:47 -0500 Received: by mail-ed1-f66.google.com with SMTP id c26so13997314eds.8 for ; Mon, 09 Dec 2019 13:13:46 -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:content-transfer-encoding; bh=3ZAoOzsHYMKfDXOLJj5uoHSZwKX72h4MMlTI4huTal4=; b=W6mljHLuB1QKV1MV560FwGm++i7fBoubbLgbVEpONn17GrKMZOmybDH/7jlbsGVJmF cp879E+659aMh57h7kPgtmnkyQuHcpDl3jf2dFvrI59xzf9qN0JyINOW+4off2ytUmFg vipqu0vE85k6VRLmuHb4RTlzBSBdUQ2ntpX4eF+Pqe8HW4KFElTi6WOVh+TSxIcXViAF 781e16UvnUeECoulj5tle+AVoj03HcxVs6rhZvyUVfpxwoUH9gsz/mr+3zkYWdxOJRFi xv+Ep8bNh1aExYX2uvXo2KKVy1Su7+kQuKRdehk6TUmce/uJ9HIieHpmIcyEE/j36a/H jMlw== 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:content-transfer-encoding; bh=3ZAoOzsHYMKfDXOLJj5uoHSZwKX72h4MMlTI4huTal4=; b=LKLvKQ3jhnXruAcA1R/H/cLjNL4Mn7ZoxKJJ9UADbXomGAJz64fx/SUNAsty2b9q/S C+CpHI72j/IWAF48FjXpIPqfWV0ozEf2Q8hbfySH6PloJ2jix6+xpKWaKQytzrbOv1XZ VN/PzH4k06m8vXE1XE9Ygr5m3ZT2Z9ZquW68HERTYqzwPMnnrH04TN4rPXpAjAa6Yoqw A7f5cYPyVfg1E10reGlWLgB4i3msQEUHJnaJnLl9WkRbTEquiyhUt8Zt5xFeMNHuUC9f SqJxqEjr8BDOSeMkQlwnMsRPxyREFQtGrl5iSXardhopoY1/uQ/KN25Sfw7roc01fQmA y3pA== X-Gm-Message-State: APjAAAUwiSyHplR1jUFAY3ziU2aDMNslz2wwt1W+wKrUq4x0pQQq8arp tGx/7D+wgix9jiFX6P//gJHriY0cI1Egp2dUjuOrxw== X-Received: by 2002:a50:fb08:: with SMTP id d8mr26688858edq.79.1575926025103; Mon, 09 Dec 2019 13:13:45 -0800 (PST) MIME-Version: 1.0 References: <20191205071953.121511-1-wvw@google.com> <20191205071953.121511-2-wvw@google.com> <92311e54-8ae8-d9a5-2597-f2b9b447cfb5@linaro.org> In-Reply-To: <92311e54-8ae8-d9a5-2597-f2b9b447cfb5@linaro.org> From: Wei Wang Date: Mon, 9 Dec 2019 13:13:33 -0800 Message-ID: Subject: Re: [PATCH v3 1/3] thermal: prevent cooling device with no type to be registered To: Daniel Lezcano Cc: Wei Wang , Zhang Rui , Eduardo Valentin , Amit Kucheria , Linux PM list , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 9, 2019 at 11:36 AM Daniel Lezcano wrote: > > On 05/12/2019 08:19, 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 > > --- > > 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_c= ore.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_n= ode *np, > > struct thermal_zone_device *pos =3D NULL; > > int result; > > > > - if (type && strlen(type) >=3D THERMAL_NAME_LENGTH) > > + if (!type || !type[0]) { > > Why not use strlen(type) =3D=3D 0 ? Checking empty is faster than getting length and this is already a pattern used in this file: https://github.com/torvalds/linux/blob/v5.4/drivers/thermal/thermal_core.c#= L63 > > > + pr_err("Error: No cooling device type defined\n"); > > return ERR_PTR(-EINVAL); > > + } > > + > > + if (strlen(type) >=3D 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", t= ype); > > return ERR_PTR(-EINVAL); > > + } > > > > cdev =3D kzalloc(sizeof(*cdev), GFP_KERNEL); > > if (!cdev) > > @@ -972,7 +982,7 @@ __thermal_cooling_device_register(struct device_nod= e *np, > > } > > > > cdev->id =3D 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 =3D np; > > > > > -- > Linaro.org =E2=94=82 Open source software for A= RM SoCs > > Follow Linaro: Facebook | > Twitter | > Blog >