Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1354510ybl; Wed, 4 Dec 2019 23:21:04 -0800 (PST) X-Google-Smtp-Source: APXvYqx8ECHaGdgfVlpEuujj3WNJ+oV7XBk5DNSzXu5fpCPb5AyAxO/Sq+S0Y4OHn6JxmuprnzX0 X-Received: by 2002:aca:ec45:: with SMTP id k66mr6147578oih.179.1575530464416; Wed, 04 Dec 2019 23:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575530464; cv=none; d=google.com; s=arc-20160816; b=UAUVtU9kSe9B0UtoX9j+V60rcy3tE8WMM1anO5je8nvmHCcuyOVYktgPemQrAFQI5L GokqGvggDsCfcj/oB9I63DwQmzLpajYfIP0kRrB39JDTuFV+yKi9Vvqr35ttbsMfyONV X76knMCwnms5joE61ippkorCkmXuyxTGDiI/vgmS61sXFJR1CtrZhmvveIBZJSHueW1r 14JoepCaI7x9Mo2ImkDS3u8l1RwchEe6AugjoeI66G87SD2CGw0tXi/4BRhqvceedgv3 LXP4Zx1VUp9ILwshN7n5Y0pu9A4shCoPeapNhVYb72SKR4C2WAT8yl6iFYQVsfEXOViQ f7CQ== 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=ev64gIbhiiWOfq6m4iAbLRYcJhqCx/lcEwnb1r5g6PE=; b=v0o3vOiGot/OjEMelnLegzSqhak1ipFeoN4T0aFc2Padt2WRipyYI5syIOzF698Lak U0fky1TRxBvI/+JKik0xKB0lJgSFcdd5Zb/a3F5BynzpLN5XpjLs4S5rfpy+ZwRixv5u jg81Zuxr/uqyrcctiIFxlCz/oUei29Aks1xGyVUPy8v9TBDz75q7J23rN7WJsna4vKpW dQ7x/8vW8aqeVV4o2yiqO/AIJshJItzQNhhT24FD1MBhaNkBa2pxxuJCQFc43VFWAq5u i2HaNMevrE1uAPD9CGQ217joF7r6G3uBdaeW/6ndXOEm30RTLuMLO0roIKvSfv6YCO/S cmRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=R+ykN4UY; 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 z3si772480oib.164.2019.12.04.23.20.44; Wed, 04 Dec 2019 23:21:04 -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=R+ykN4UY; 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 S1726268AbfLEHUQ (ORCPT + 99 others); Thu, 5 Dec 2019 02:20:16 -0500 Received: from mail-pl1-f202.google.com ([209.85.214.202]:42724 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbfLEHUP (ORCPT ); Thu, 5 Dec 2019 02:20:15 -0500 Received: by mail-pl1-f202.google.com with SMTP id 30so1131784plb.9 for ; Wed, 04 Dec 2019 23:20:14 -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=ev64gIbhiiWOfq6m4iAbLRYcJhqCx/lcEwnb1r5g6PE=; b=R+ykN4UYQcA+9UAFBvvgSklElgRJSGCbdjk3VUbcEctURsnU5CwuNXWO88/2LmVMdq r6nn8FUN5jLomBx4p9FG8TEWWtx8HsIrIwaBsiY5fJpb1Nq3Ihrigwf0e+ZNmmAA37An TqtPQrVKW6+ijvL8aWf5sioqroZHaAk1+1kuYyG3n1Md4YCKdf4AXFAnjATz5cha+KMo B/PNQWIKHR7+uvG0qGiYzEsiCZT9Pb38p95lG888xLi8+VbGTuVOVNJ6/YLvBDzz+kUr wLoBayDpo9fpvSJCH9vpLUbLlCUlC0dLETJAYhdav90zY411kNHv5cX88Agdn5JdNPMt Hsug== 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=ev64gIbhiiWOfq6m4iAbLRYcJhqCx/lcEwnb1r5g6PE=; b=iICAUlzulLhXvID+AMhaXatSaC0LpiEuqOtHdeUBkiFNSHy4MiWcNg9fj1Q6UQCXMg T5VoQCPhBe2Vesb8kX/+BdOXriE7ic6pUzAzmk99iG6/fxh9E7yb1cHhLqE/oEpZnV01 svRlswgpdHu410ye+6pj0sx2MjsIF/h+i/C2jHBWuJ7F9gsSfnPOwolz4TXorjAhitt3 I9MZ1eMPgkLUEtlCSUUF723mrXWr0aeeP3BV1z3pnC6Ba4ZrCBxsXr7x9jMIb35xWZKw DNUlyiAGLtOlf6pAhjxkdpxFZTtmQOhxSp7lxqXNHDCZMsD/Z9bq1BjtCgWTKp4j7Lb+ UIqw== X-Gm-Message-State: APjAAAVItnfjAfBOk5VxqujVN9ot1AACwfGLj60Cl7k1zFh5a9XL9LUE s2yBJdAQhg5UBGZh8GSiTZeUkqc= X-Received: by 2002:a65:5a4d:: with SMTP id z13mr7837344pgs.21.1575530414350; Wed, 04 Dec 2019 23:20:14 -0800 (PST) Date: Wed, 4 Dec 2019 23:19:51 -0800 In-Reply-To: <20191205071953.121511-1-wvw@google.com> Message-Id: <20191205071953.121511-2-wvw@google.com> Mime-Version: 1.0 References: <20191205071953.121511-1-wvw@google.com> X-Mailer: git-send-email 2.24.0.393.g34dc348eaf-goog Subject: [PATCH v3 1/3] thermal: prevent cooling device with no type to be registered 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 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_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