Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3696079imm; Mon, 8 Oct 2018 08:08:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV61pgnzn2M6s8CdetWMx/CQu574bbCnsZpKMzILTKWEppxR7a27BTNn/oLIWnPdN+9nbZpYL X-Received: by 2002:a17:902:8a4:: with SMTP id 33-v6mr24633101pll.65.1539011301433; Mon, 08 Oct 2018 08:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539011301; cv=none; d=google.com; s=arc-20160816; b=e2AR+eJY0VnpG7272EtTNYaNDY3qb27aaNwzm1/BZIjnEzw2CVX7CdLAEJMzKDG/qL 8sjqb4bgIpBXYRmdk9g+VrBLPnG+eKDWT981hhNpJ6cqSDS0AlYHSbzxRuNMi4DkUV7s QnaMIy+XijjAdOnfXOHkhtKXFxIsupp81s25GulEbO6UJTD2a7juhA9QJpZ+j6V7Crj7 QKoxEJgiApuj3MrV0cF/AQs9QrCPW1x/Jvm98627qGwcTQfCJJ0qW1ZphjzLMAGUjf3f fsa6Ppz2glQxILaZ1hl9okl1ZmeeLNembGAKtvgmmlCaZBLpLH4dj6dDSMGz6Ys8KMul 4RSg== 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=TzONM/HFgtIRfO/xuMLQirIIs3OiG3wnRauL3rJ72XM=; b=0krAIZg2VxhnvNslN5vYStOW0O7zJ/mDx0cCtS8Gg0ueT9wskdr8nf9DD3ydm3UDCY YX5fiOy709GkOuDuFrAHJ/vPgjA8Twf3dUZlgO9zJFmfWhOlBdjasV3JYwfJVoHc4E+T NYvCb2nllUE3znqz8HG3921Upbdxjl9Iux/RoySQZ81tnC6YCSYiwIaGq/AFgGn6syVu c/6oRDSkZWBarhlgmimuRM4sAnJXgqMBG85/PZiUfKTviB/pltpRWKAffed3eVLl5bgw 3YlRC6IgCSi+z9kqWbBZKSheFLmDVnRtvVO00NvD4ba5NWDsB9Oo3Iuo9zu5of7a6ibm V8iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ICpQhcYY; 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 v3-v6si19272381pfd.125.2018.10.08.08.08.01; Mon, 08 Oct 2018 08:08:21 -0700 (PDT) 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=ICpQhcYY; 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 S1726525AbeJHWTz (ORCPT + 99 others); Mon, 8 Oct 2018 18:19:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:51156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbeJHWTz (ORCPT ); Mon, 8 Oct 2018 18:19:55 -0400 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (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 182BB2087D; Mon, 8 Oct 2018 15:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539011264; bh=6NReo/4Nn2G9oD/PzpWTLB6Cp2barDSEvWR9u6hhmgs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ICpQhcYYoGOkmvuNwSqLiqB0Rn9oq/abHrVMcUo8lLE5D4We9LtPXscxTGW3dS9ox IxKTlyjWjwCERhEzr6vomF5hjKSh+LTJkVET3WMJ8oTj6i+ZCx26ij7sL35gW4FCFM hHEYVx8H2dzhmqibID76jDe5o8RKLH2wTSgLKZnI= Received: by mail-qt1-f169.google.com with SMTP id b4-v6so13215031qtc.7; Mon, 08 Oct 2018 08:07:44 -0700 (PDT) X-Gm-Message-State: ABuFfoim6jJPJV9YZpYWDBKEv9x5oGwXTKtvzddpNihE7FJBsMZHVn4L PuOQSVBW4EQZbe1En3G08BtaQ8zi/KViUSLETw== X-Received: by 2002:a0c:bc03:: with SMTP id j3-v6mr19931302qvg.77.1539011263231; Mon, 08 Oct 2018 08:07:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Rob Herring Date: Mon, 8 Oct 2018 10:07:32 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] of: base: Change logic in of_alias_get_alias_list() To: Michal Simek Cc: "linux-kernel@vger.kernel.org" , Michal Simek , Geert Uytterhoeven , Greg Kroah-Hartman , devicetree@vger.kernel.org, Jiri Slaby , "open list:SERIAL DRIVERS" , Frank Rowand , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" 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 Mon, Oct 8, 2018 at 7:19 AM Michal Simek wrote: > > Check compatible string first before setting up bit in bitmap to also > cover cases that allocated bitfield is not big enough. > Show warning about it but let driver to continue to work with allocated > bitfield to keep at least some devices (included console which > is commonly close to serial0) to work. > > Fixes: b1078c355d76 ("of: base: Introduce of_alias_get_alias_list() to check alias IDs") > Fixes: ae1cca3fa347 ("serial: uartps: Change uart ID port allocation") > Signed-off-by: Michal Simek > --- > > I have looked at it and I don't think there should be necessary to > report error immediately back with partially initialized bitfield. > The reason is that still there could be a console device which is most > likely below that max limit and it is worth to return at least that nbits > properly filled. > It will also enable cases that you can still continue to use aliases > higher then fields prepared for devices without alias. Seems reasonable. Plus if you had a new dtb which added an alias greater than what the OS version supports, you would break that system. > > To be fixed patches are present in tty-next branch. > > --- > drivers/of/base.c | 22 ++++++++++++---------- > drivers/tty/serial/xilinx_uartps.c | 2 +- > 2 files changed, 13 insertions(+), 11 deletions(-) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index 908de45f966b..0b9611e196d1 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -1953,13 +1953,15 @@ int of_alias_get_id(struct device_node *np, const char *stem) > * The function travels the lookup table to record alias ids for the given > * device match structures and alias stem. > * > - * Return: 0 or -ENOSYS when !CONFIG_OF > + * Return: 0 or -ENOSYS when !CONFIG_OF or > + * -EINVAL if alias ID is greater then allocated nbits I think EOVERFLOW or ERANGE would be better as those are less common and I take EINVAL as the caller made an error. > */ > int of_alias_get_alias_list(const struct of_device_id *matches, > const char *stem, unsigned long *bitmap, > unsigned int nbits) > { > struct alias_prop *app; > + int ret = 0; > > /* Zero bitmap field to make sure that all the time it is clean */ > bitmap_zero(bitmap, nbits); > @@ -1976,21 +1978,21 @@ int of_alias_get_alias_list(const struct of_device_id *matches, > continue; > } > > - if (app->id >= nbits) { > - pr_debug("%s: ID %d greater then bitmap field %d\n", > - __func__, app->id, nbits); > - continue; > - } > - > if (of_match_node(matches, app->np)) { > pr_debug("%s: Allocated ID %d\n", __func__, app->id); > - set_bit(app->id, bitmap); > + > + if (app->id >= nbits) { > + pr_warn("%s: ID %d >= than bitmap field %d\n", > + __func__, app->id, nbits); > + ret = -EINVAL; > + } else { > + set_bit(app->id, bitmap); > + } > } > - /* Alias exists but is not compatible with matches */ > } > mutex_unlock(&of_mutex); > > - return 0; > + return ret; > } > EXPORT_SYMBOL_GPL(of_alias_get_alias_list); > > diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c > index d452dceb0cb3..29a18103182d 100644 > --- a/drivers/tty/serial/xilinx_uartps.c > +++ b/drivers/tty/serial/xilinx_uartps.c > @@ -1393,7 +1393,7 @@ static int cdns_get_id(struct platform_device *pdev) > if (!alias_bitmap_initialized) { > ret = of_alias_get_alias_list(cdns_uart_of_match, "serial", > alias_bitmap, MAX_UART_INSTANCES); > - if (ret) { > + if (ret && ret != -EINVAL) { > mutex_unlock(&bitmap_lock); > return ret; > } > -- > 1.9.1 >