Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2276475ybt; Tue, 16 Jun 2020 01:34:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOuWuOWZ2mzXAU5SPW/iGMZc5lSHP4blUskbQQGYdYXYkrCYY/6o1Doh5YdWPUFTNcvbWf X-Received: by 2002:a17:906:fb9b:: with SMTP id lr27mr1647933ejb.405.1592296471952; Tue, 16 Jun 2020 01:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592296471; cv=none; d=google.com; s=arc-20160816; b=NayGq3lVSMlWct6HJqM09Xmf+a/Omn15bKYv+//eLXPmLAw61/syhjiB7bGg5rH71x gBlcKqTtEY+2LEejtheV0WjpRk1NDagKS8HAfOsIOSzHgGc09Z42sBLumXblWeonNGz2 bWakibl5KV+/EHmFoybO66MZagkzME7GqxatudPeaJVtpG+A6/XXSoSi5LA3zsyA5q7U PMGzO6xx1BV+19Ep/C0QQ+ksCMbyJ38IsUtJb1oYhVyC/jVA9gfssaOuaYvSv9563Ezu 3LHX6u52P2hem3q84KXxb8Hx4EYzkbz9bWGnKVc/HTY84lEH/WycZpHFj0zB9ULpT+S6 AbCQ== 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=sQ4U7wvoNlcpjuMW/4KAQuHPsQCChERlSO2SrjCLc4A=; b=dWvDAcSTMGQ6GF6b0vsWmVcaVyEh++0hqZmBm1+KNSa1H6CjbV1fxBO0P1QvCxLd65 nAylLI8VRNIWICniykUGNi+viAU8msD07/2aXEqthf7L0FjbHBpMAzoCWqwXv/9VALGt ZWrh6MdRz4JliXSuTawJ5nbva4RiLnBgJc8lGDrAOsYkappyKk1ShUFsEAVOwIDOH8Ah Z8RAhuJiim4vXstM+u1HLVCe4pItL5ODFK6AfJIK4stGl38osTqJd7OUzsyU9XjOcZzQ zXFFDdXXqkGYcREYvL6NwOhzeMttmSh0fhF8WxUAyLtiA/RZhMRkTLVuvc1kfq5gFc8F iPrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yzgs82Ty; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si10294227edc.599.2020.06.16.01.34.06; Tue, 16 Jun 2020 01:34:31 -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=@linaro.org header.s=google header.b=yzgs82Ty; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728086AbgFPIcH (ORCPT + 99 others); Tue, 16 Jun 2020 04:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728074AbgFPIcH (ORCPT ); Tue, 16 Jun 2020 04:32:07 -0400 Received: from mail-lj1-x244.google.com (mail-lj1-x244.google.com [IPv6:2a00:1450:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8381C03E97C for ; Tue, 16 Jun 2020 01:32:06 -0700 (PDT) Received: by mail-lj1-x244.google.com with SMTP id s1so22496356ljo.0 for ; Tue, 16 Jun 2020 01:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sQ4U7wvoNlcpjuMW/4KAQuHPsQCChERlSO2SrjCLc4A=; b=yzgs82TyqjiolbSZa0hACzF4gN7GCdrUZ3PkJIwNsxrwGymEWug+COKC95YBk6TI0K 2Y0WbWcE0rB11ecpIHasmBOEfu2LHU1jVxms4CkS6c1YBhHphAVGDqxKnQPW4PBBc7hb LMdJwAntiTOBJmW2XA6P3lnRabzZ3UT3E9uy8o/U1SwZ5oitYwRLHc5WSAN8DB/8WxGH VrB15nm/FvXI/F5bPdrN/KsIQp6inbymvEpyLN7rdC7zEFqzsH+Jxw7zBeSbaDF9hj4Z jaXPYaexNoE0Z92Ldpp3NqRRd9Su8ihOkFK3xJAvMTKv498p1DzKxsLxehhJydEQaZ+i fWig== 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; bh=sQ4U7wvoNlcpjuMW/4KAQuHPsQCChERlSO2SrjCLc4A=; b=GjziAUHb6WiJRG9pasVH061zB/I6jF91nDSs5u53JBrqxKJLBuxouvdMijWNuKyMEH kelWx3LNz8Jjq8Rvtroh5FxjIrcqINpAyp2vZYZA0cH8HCb+wltLXStBHOVpIjvSG+Ss D95f+Gbl6sc/+2XAA/3wJHuL7c64oh1SJLgQVryZlOm409pzbv2zvNH0ruOJvyWSRbKY aiZxefnJoO/B5SPYhAmCpCxHaLVBn/i67M6UbBV3BN/QjVKtepqdYgwS940pN5c3CN0V VPZi2Y9hSTUMNHLtGJ0knLJ7E7NMv6flm68096DLRg0FiWUERNfNMsTN/R+Q4S+5sWQh hU1A== X-Gm-Message-State: AOAM531QvF9GhTRmqGLcM3wDwhQ26ux4qd/4VimP1ENHbAuzqekH9Mrp YIshRs1IQIFvSmLisy64WVNV1MrXeWiF/YiG3MQIrQ== X-Received: by 2002:a2e:350a:: with SMTP id z10mr837916ljz.104.1592296325111; Tue, 16 Jun 2020 01:32:05 -0700 (PDT) MIME-Version: 1.0 References: <20200608125143.GA2789203@x1> In-Reply-To: <20200608125143.GA2789203@x1> From: Linus Walleij Date: Tue, 16 Jun 2020 10:31:54 +0200 Message-ID: Subject: Re: [PATCH v2] pinctrl-single: fix pcs_parse_pinconf() return value To: Drew Fustini Cc: Tony Lindgren , Haojian Zhuang , Linux ARM , Linux-OMAP , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" , Grygorii Strashko , Jason Kridner , Robert Nelson 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, Jun 8, 2020 at 2:51 PM Drew Fustini wrote: > 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 Patch applied as non-critical (for-next) fix. If there is no hurry let's merge it this way with lots of testing along the way. Yours, Linus Walleij