Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp594286imu; Fri, 25 Jan 2019 07:36:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN60iQi8AQ3Fm2KIT+x7Ub8TCpswTTQyF31+zS60mV6dhbAUWRCrxYrkA0R54SQpTr+VbitJ X-Received: by 2002:a63:193:: with SMTP id 141mr10480295pgb.136.1548430573211; Fri, 25 Jan 2019 07:36:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548430573; cv=none; d=google.com; s=arc-20160816; b=WJHU8ov+4RM7vqqLd+RdBcOs95sSfLNMQb9RYOuyOej5WXqHFriw0k+4gW+oaNHMp3 G8SAGnJmeUWz4hearStrT2oUnXHF9OHLR/pxtjyiWtknoP+fdtPL9biYysB/tJ+FF1iA fomVT0c6Jw1imMvEFQOoUGsCNBsNSaET0+QeJdBg/PpWaq29f1T6AFR6jAuqlBYnI3lh CR2MMIN/HXAl5hsiYEru1fu2yyYxu0R4TwndqJdSxfgswafbnY237IbYlrVWxEa36HZt NlJgKiDl86+96BIbczx4dgsWqfqfQwtTLEo4WHN4kpjv3NBSbWBcgpxWJ0/PFyv9Rcpi P5rw== 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=+JPcb9R1YcJsoxyCNyLm/Lzl2FdzGICmcJUlu2x8V9s=; b=nG0U+wYG/5HhEyahqADGdR0p0VUS/4vPRQG2pQp09U8vQMUmEBKRJ0QjzjuDfaloWm zda2/STca2PiOgzGZed1d8f64+PjmordQ/AGVaVy91bMfBHVTx3NOlGT7cgHTJYDrIn4 oHHEc22qJbn05IL1sGVh6FS14lGscMkYmyK0MTUU37wVHpq2L9YegIHuasPifd8Bvx2T 1Yjwkm0vg0r5HQkl7YP8Vy9CGw+sJfW2HsiaOBq88cpB7yP4BzhRBKSVMbNxne1c6LZN ho2WZCjZM+vFJBIY47zyJu5sSJxcU9p9GhJqGY0W01QuvTEmaQQN3nEvUGWXpsJebv4O oGWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mhToJIad; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c8si26216378pfe.243.2019.01.25.07.35.57; Fri, 25 Jan 2019 07:36:13 -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=@kernel.org header.s=default header.b=mhToJIad; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728621AbfAYPdu (ORCPT + 99 others); Fri, 25 Jan 2019 10:33:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:60266 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726256AbfAYPdu (ORCPT ); Fri, 25 Jan 2019 10:33:50 -0500 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6E1F3218DE; Fri, 25 Jan 2019 15:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548430428; bh=WjkqafWbRIcHoKvZHTxSFOYP9foD21IA9880hyor6PY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mhToJIad9MPm6BCQWUIguEEwRFF68Iz2qkd6bvNQ7n1evDNx4yTI44We/ASyD2ez6 HIrkiO59EfWBFoYh1aCA4+Bg9ICR33f6kB/zccX96Q8n27rbiR6gHgsfXtpzt+vp3Z joTIpxeTqRZEH8lkFzu/PEKkZtYcEqt2As1jF2is= Received: by mail-qt1-f174.google.com with SMTP id l11so11127322qtp.0; Fri, 25 Jan 2019 07:33:48 -0800 (PST) X-Gm-Message-State: AJcUukdiq7ZaoavYEoVT1P9URikeM9lqdmddzqUq/VlBz5iS3rbu06u9 qGeD5fZpvWPx7CTSDUG+d1Ij6rgpsYy+BvhlAQ== X-Received: by 2002:aed:3ecf:: with SMTP id o15mr11596557qtf.26.1548430427574; Fri, 25 Jan 2019 07:33:47 -0800 (PST) MIME-Version: 1.0 References: <20190124200825.2611-1-f.fainelli@gmail.com> <1a19b5f3-1387-0e6d-2d84-1b61079b4efb@gmail.com> <3e63d0c3-cb92-5caa-c0db-a04ef8fb5393@gmail.com> <04286c55-b995-3c5b-dc03-9f3c46d6376b@gmail.com> In-Reply-To: From: Rob Herring Date: Fri, 25 Jan 2019 09:33:35 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: Make of_node_name_eq() case insensitive To: Florian Fainelli Cc: Frank Rowand , "linux-kernel@vger.kernel.org" , vivien.didelot@gmail.com, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" 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, Jan 24, 2019 at 11:00 PM Florian Fainelli wrote: > > > > On 1/24/19 6:06 PM, Frank Rowand wrote: > > On 1/24/19 5:20 PM, Florian Fainelli wrote: > >> > >> > >> On 1/24/19 3:45 PM, Frank Rowand wrote: > >>> On 1/24/19 12:08 PM, Florian Fainelli wrote: > >>>> Since c32569e358ad ("regulator: Use of_node_name_eq for node name > >>>> comparisons") Vivien reported the mc13892-regulator complaining about > >>>> not being able to find regulators. > >>>> > >>>> This is because prior to that commit we used of_node_cmp() to compare > >>>> the regulator array passed from mc13892_regulators down to > >>>> mc13xxx_parse_regulators_dt() and they are all defined in uppercase > >>>> letters by the MC13892_*_DEFINE* macros, whereas they are defined as > >>>> lowercase in the DTS. > >>>> > >>>> Fix this by use strncasecmp() since that makes sure the comparison is > >>>> case insensitive like what of_node_cmp() did. > >>>> > >>>> Reported-by: Vivien Didelot > >>>> Fixes: c32569e358ad ("regulator: Use of_node_name_eq for node name comparisons") > >>>> Signed-off-by: Florian Fainelli > >>>> --- > >>>> drivers/of/base.c | 3 ++- > >>>> 1 file changed, 2 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/drivers/of/base.c b/drivers/of/base.c > >>>> index 5226e898476e..ff47c86277cb 100644 > >>>> --- a/drivers/of/base.c > >>>> +++ b/drivers/of/base.c > >>>> @@ -66,7 +66,8 @@ bool of_node_name_eq(const struct device_node *np, const char *name) > >>>> node_name = kbasename(np->full_name); > >>>> len = strchrnul(node_name, '@') - node_name; > >>>> > >>>> - return (strlen(name) == len) && (strncmp(node_name, name, len) == 0); > >>>> + return (strlen(name) == len) && > >>>> + (strncasecmp(node_name, name, len) == 0); > >>>> } > >>>> EXPORT_SYMBOL(of_node_name_eq); > >>>> > >>>> > >>> > >>> Node names are case sensitive. Please fix mc13xxx_parse_regulators_dt() to > >>> properly handle case instead of changing of_node_name_eq(). > >> > >> Fair enough, should we issue a warning if np->full_name contains upper > >> case while name does not (and vice versa) to help troubleshoot cases > >> like the one we found with Vivien? > > > > It seems like a lot of work to detect that specific case. If anything, > > maybe just add some text to the existing "Unknown regulator: ..." warning > > in mc13xxx_parse_regulators_dt() to mention that case matters. > > I was not thinking about something very clever, just issue a warning > like this, completely untested and likely flawed: > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index 5226e898476e..2505286c875b 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -58,6 +58,7 @@ DEFINE_RAW_SPINLOCK(devtree_lock); > bool of_node_name_eq(const struct device_node *np, const char *name) > { > const char *node_name; > + int ret1, ret2; > size_t len; > > if (!np) > @@ -66,7 +67,12 @@ bool of_node_name_eq(const struct device_node *np, > const char *name) > node_name = kbasename(np->full_name); > len = strchrnul(node_name, '@') - node_name; > > - return (strlen(name) == len) && (strncmp(node_name, name, len) > == 0); > + ret1 = strncmp(node_name, name, len); > + ret2 = strncasecmp(node_name, len); > + > + WARN(ret1 ^ ret2, "Comparing case sensitive names!"); > + > + return (strlen(name) == len && (strncmp(node_name, name, len) == 0); If it comes to this, I'd rather not always do 3 string compares. > } > EXPORT_SYMBOL(of_node_name_eq); > > > My concern is that we have identified one place here where the > conversion to of_node_name_eq() broke that particular driver in fact, > all other regulator drivers but qcom-rpmh-regulator.c that use > of_node_name_eq() are broken after that change, but presumably this is > not the only place in the kernel where things could break, so having a > warning could potentially help (also adding the backtrace which is neat). Most modern DT's don't really rely on the node names. Regulators are the oddball. I checked all the other affected regulator drivers. da9052 is also affected. IMO, we should fix the drivers and I'm sending out patches to do that. > What should the fix look like though? Add an of_node_casename_eq() and > use it, revert Rob's commit that changes these regulators to use > of_node_name_eq()? No, we don't want to add of_node_casename_eq. We may have to internally go back to case insensitive compare, but I'd like to avoid that and fix any specific cases if possible. > I don't know the regulator framework enough to know whether forcibly > making the names lowercase is not breaking sysfs/debugfs... Userspace relying on specific regulator names seems questionable to me. Certainly, debugfs is not an ABI. Rob