Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2658180pxa; Mon, 17 Aug 2020 15:44:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeYHb+9n1J65+Sg939GjIx6frS79tkrOyTYLqX+ZxSofBgsFIO6W+II6A2X3NF4TfuZcP8 X-Received: by 2002:a17:906:7b83:: with SMTP id s3mr17112414ejo.2.1597704295364; Mon, 17 Aug 2020 15:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704295; cv=none; d=google.com; s=arc-20160816; b=kzgqpqeaYNzY8K6VBKKRUZ6ZsqaKGi6nUIHJOAZ51+VrKEXC7iT2aR5dI721yvYTA4 CY4LeaqyY9QE6MJKj17An8NDJ/2O6ao3IhtXLfjnDk9eQRAbbhE5g+d8vpokuju++KyJ Nlt6NsF6wPEAEj/tSEF/zFtgI/GS0dE75Oo+3fqF3mMAvdzOsAkvTqFsaY77JSBcszBd bbfNmGsRCh9xgyrEhW+zHEysttY23ltX+W3lQABwn/3DcgujJyWs8uoko5ux2FWxuMNi bs5HzMLisQIV5mdnUdhRpqSN3Ge9D93g2UD7TwY+YOE0d1uoM7aJVRwduWFK7OTiOn3a Rcqg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=HlltLXv8XPNJgPbxxPsAmDcihj+tPA13M1K3GZ3xw+A=; b=UFn0uM2jKcKzcmV3vtVGCrD6z0YS2/A1l51qF7bKA/DiQ09PsGyZcwR/w+ZScUeVG+ jn/y/j4ZYma56KjbF8ngq3TzrJZY1xhEySWObeerYTNRJAbZJHUNRkPePnMv46zl7WvJ W5xwdT8no5GkwylS/x3enDm1Yx1vUnyt0aoCH2lGb80/oIO8tmztI6G2+DE5Di/mGhFp uurtQlD1PNDbihAUSap5B0oxHWR866Q5CY9fDPKKODiXrySYJ0FDGkA47JB5oTp06qFl V6V5vKKEjYjWEPhK68N3eK+gGPc5K/EBKXtPoW4GajDDXOlCavDjLamfiupC+hHbgHDm 5PWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ug7RWLFA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd9si12170788edb.340.2020.08.17.15.44.32; Mon, 17 Aug 2020 15:44:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ug7RWLFA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391646AbgHQSsF (ORCPT + 99 others); Mon, 17 Aug 2020 14:48:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:42988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388019AbgHQPz2 (ORCPT ); Mon, 17 Aug 2020 11:55:28 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 99077208B3; Mon, 17 Aug 2020 15:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597679718; bh=lcURmuB0sanhhJVraJDp8d0WGsWJPNVtwW8HalFB16c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ug7RWLFASXd1JA5odfFCGYzXW+LdtAp2VrI87865/mK3BIhL2tBPdDIMXmasc6IKr PSA8Y6vDduZUksOkIdm2dE0HEUK8kOrl/svX81oYDD8kK0J/F99gX3o3HlzYIJPDKa 1l6ee1IaZzFoN86bAOiBP/4eTUuNx72Is1sTemiw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Drew Fustini , Tony Lindgren , Linus Walleij , Sasha Levin Subject: [PATCH 5.7 310/393] pinctrl-single: fix pcs_parse_pinconf() return value Date: Mon, 17 Aug 2020 17:16:00 +0200 Message-Id: <20200817143834.648898215@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143819.579311991@linuxfoundation.org> References: <20200817143819.579311991@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Drew Fustini [ Upstream commit f46fe79ff1b65692a65266a5bec6dbe2bf7fc70f ] This patch causes pcs_parse_pinconf() to return -ENOTSUPP when no pinctrl_map is added. The current behavior is to return 0 when !PCS_HAS_PINCONF or !nconfs. Thus pcs_parse_one_pinctrl_entry() incorrectly assumes that a map was added and sets num_maps = 2. Analysis: ========= The function pcs_parse_one_pinctrl_entry() calls pcs_parse_pinconf() if PCS_HAS_PINCONF is enabled. The function pcs_parse_pinconf() returns 0 to indicate there was no error and num_maps is then set to 2: 980 static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs, 981 struct device_node *np, 982 struct pinctrl_map **map, 983 unsigned *num_maps, 984 const char **pgnames) 985 { 1053 (*map)->type = PIN_MAP_TYPE_MUX_GROUP; 1054 (*map)->data.mux.group = np->name; 1055 (*map)->data.mux.function = np->name; 1056 1057 if (PCS_HAS_PINCONF && function) { 1058 res = pcs_parse_pinconf(pcs, np, function, map); 1059 if (res) 1060 goto free_pingroups; 1061 *num_maps = 2; 1062 } else { 1063 *num_maps = 1; 1064 } However, pcs_parse_pinconf() will also return 0 if !PCS_HAS_PINCONF or !nconfs. I believe these conditions should indicate that no map was added by returning -ENOTSUPP. Otherwise pcs_parse_one_pinctrl_entry() will set num_maps = 2 even though no maps were successfully added, as it does not reach "m++" on line 940: 895 static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np, 896 struct pcs_function *func, 897 struct pinctrl_map **map) 898 899 { 900 struct pinctrl_map *m = *map; 917 /* If pinconf isn't supported, don't parse properties in below. */ 918 if (!PCS_HAS_PINCONF) 919 return 0; 920 921 /* cacluate how much properties are supported in current node */ 922 for (i = 0; i < ARRAY_SIZE(prop2); i++) { 923 if (of_find_property(np, prop2[i].name, NULL)) 924 nconfs++; 925 } 926 for (i = 0; i < ARRAY_SIZE(prop4); i++) { 927 if (of_find_property(np, prop4[i].name, NULL)) 928 nconfs++; 929 } 930 if (!nconfs) 919 return 0; 932 933 func->conf = devm_kcalloc(pcs->dev, 934 nconfs, sizeof(struct pcs_conf_vals), 935 GFP_KERNEL); 936 if (!func->conf) 937 return -ENOMEM; 938 func->nconfs = nconfs; 939 conf = &(func->conf[0]); 940 m++; This situtation will cause a boot failure [0] on the BeagleBone Black (AM3358) when am33xx_pinmux node in arch/arm/boot/dts/am33xx-l4.dtsi has compatible = "pinconf-single" instead of "pinctrl-single". The patch fixes this issue by returning -ENOSUPP when !PCS_HAS_PINCONF or !nconfs, so that pcs_parse_one_pinctrl_entry() will know that no map was added. Logic is also added to pcs_parse_one_pinctrl_entry() to distinguish between -ENOSUPP and other errors. In the case of -ENOSUPP, num_maps is set to 1 as it is valid for pinconf to be enabled and a given pin group to not any pinconf properties. [0] https://lore.kernel.org/linux-omap/20200529175544.GA3766151@x1/ Fixes: 9dddb4df90d1 ("pinctrl: single: support generic pinconf") Signed-off-by: Drew Fustini Acked-by: Tony Lindgren Link: https://lore.kernel.org/r/20200608125143.GA2789203@x1 Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/pinctrl-single.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 1e0614daee9bf..a9d511982780c 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -916,7 +916,7 @@ static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np, /* If pinconf isn't supported, don't parse properties in below. */ if (!PCS_HAS_PINCONF) - return 0; + return -ENOTSUPP; /* cacluate how much properties are supported in current node */ for (i = 0; i < ARRAY_SIZE(prop2); i++) { @@ -928,7 +928,7 @@ static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np, nconfs++; } if (!nconfs) - return 0; + return -ENOTSUPP; func->conf = devm_kcalloc(pcs->dev, nconfs, sizeof(struct pcs_conf_vals), @@ -1056,9 +1056,12 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs, if (PCS_HAS_PINCONF && function) { res = pcs_parse_pinconf(pcs, np, function, map); - if (res) + if (res == 0) + *num_maps = 2; + else if (res == -ENOTSUPP) + *num_maps = 1; + else goto free_pingroups; - *num_maps = 2; } else { *num_maps = 1; } -- 2.25.1