Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2512115imm; Mon, 24 Sep 2018 05:43:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV60WEZEhw9q7P8yAB2fXV3wfhdGJK0Na9wkRRi8WsRx1qJmGEQ0wHSXUov5tHmveRYc1lDE/ X-Received: by 2002:a63:501:: with SMTP id 1-v6mr9187486pgf.205.1537792999520; Mon, 24 Sep 2018 05:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792999; cv=none; d=google.com; s=arc-20160816; b=NUETpqEbGi/bZdzrk3rx0QDPmDf4+eqBhV4dN+4rIwphW8/K3yXyWEISlnCAjFzzkS E/E83xq6+SnwFCMsWfBpJfBP7VgyokJKSv5Lfokrp2f1p+atUcYsDE36UTBb6u+rbLc9 aPg+4JuroW+8gnk8DlUCcUaWOYntbfm12UzfFlr3lc472cKWBWVEuntVCT40ysoCTm0E 9BxBhZLfjX9wLwO9DpFDixuu1WE+dmKWHIWvKf7/GtmPUR1OxGT7/JmsSRM6DhM+08Yq EiG/iaST4x9FWcOYzaVn1umnrgQXHbrqN31SuZkw6Fh5RAuNc8rEKbflsr2JhxaIYP3G yMnQ== 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; bh=Pki0OQ28oJuFErfVMeApIQ7gy05SbvlW6mkoJ7ySy1g=; b=Gl3hIx/mMnuj0mYchoduwJwsQ2g9eryCyFoYv30q/Wq6Tk9YWwRG5AqSk+XhoLSepR bTwgYg6FK3A/tx/MiN7p/sxtHbR/SFbqvxxJyQ65KJE1NePyM056yAnuU+TjFJt4BQxB 5yhwSFwzP7o+f9AYzbHTGZpueRYnjIJJm1g9BzponC1PdCQpcTm7aAUeHJAA6dX12Ipk R+DYFcx3Z/D4+DIcEZHmcMfgq037pYYH1T0vg4uInYXzwj5QpG2gRwBlVSrmW3JGPyri ZHOIZC2GoLe5m4HGUtxAq32zf5YLcP7lU4yeCRsX7HCQQwlDNI1ZDPsUuSBs9vXbcwSw pCNw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i190-v6si571028pge.83.2018.09.24.05.43.04; Mon, 24 Sep 2018 05:43:19 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388669AbeIXSmv (ORCPT + 99 others); Mon, 24 Sep 2018 14:42:51 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59048 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387828AbeIXSmv (ORCPT ); Mon, 24 Sep 2018 14:42:51 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id ACA79109E; Mon, 24 Sep 2018 12:40:51 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "H. Nikolaus Schaller" , Christ van Willegen , Haojian Zhuang , Paul Cercueil , Sean Wang , Jacopo Mondi , Tony Lindgren , Andy Shevchenko , Linus Walleij , Sasha Levin Subject: [PATCH 4.18 163/235] pinctrl: rza1: Fix selector use for groups and functions Date: Mon, 24 Sep 2018 13:52:29 +0200 Message-Id: <20180924113121.397382619@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tony Lindgren [ Upstream commit dc4003d260594aa300028c3c5d040c5719abd19b ] We must use a mutex around the generic_add functions and save the function and group selector in case we need to remove them. Otherwise the selector use will be racy for deferred probe at least. Fixes: 5a49b644b307 ("pinctrl: Renesas RZ/A1 pin and gpio controller") Reported-by: H. Nikolaus Schaller Cc: Christ van Willegen Cc: Haojian Zhuang Cc: Paul Cercueil Cc: Sean Wang Acked-by: Jacopo Mondi Signed-off-by: Tony Lindgren Tested-By: H. Nikolaus Schaller Reviewed-by: Andy Shevchenko Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/pinctrl-rza1.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) --- a/drivers/pinctrl/pinctrl-rza1.c +++ b/drivers/pinctrl/pinctrl-rza1.c @@ -1006,6 +1006,7 @@ static int rza1_dt_node_to_map(struct pi const char *grpname; const char **fngrps; int ret, npins; + int gsel, fsel; npins = rza1_dt_node_pin_count(np); if (npins < 0) { @@ -1055,18 +1056,19 @@ static int rza1_dt_node_to_map(struct pi fngrps[0] = grpname; mutex_lock(&rza1_pctl->mutex); - ret = pinctrl_generic_add_group(pctldev, grpname, grpins, npins, - NULL); - if (ret) { + gsel = pinctrl_generic_add_group(pctldev, grpname, grpins, npins, + NULL); + if (gsel < 0) { mutex_unlock(&rza1_pctl->mutex); - return ret; + return gsel; } - ret = pinmux_generic_add_function(pctldev, grpname, fngrps, 1, - mux_confs); - if (ret) + fsel = pinmux_generic_add_function(pctldev, grpname, fngrps, 1, + mux_confs); + if (fsel < 0) { + ret = fsel; goto remove_group; - mutex_unlock(&rza1_pctl->mutex); + } dev_info(rza1_pctl->dev, "Parsed function and group %s with %d pins\n", grpname, npins); @@ -1083,15 +1085,15 @@ static int rza1_dt_node_to_map(struct pi (*map)->data.mux.group = np->name; (*map)->data.mux.function = np->name; *num_maps = 1; + mutex_unlock(&rza1_pctl->mutex); return 0; remove_function: - mutex_lock(&rza1_pctl->mutex); - pinmux_generic_remove_last_function(pctldev); + pinmux_generic_remove_function(pctldev, fsel); remove_group: - pinctrl_generic_remove_last_group(pctldev); + pinctrl_generic_remove_group(pctldev, gsel); mutex_unlock(&rza1_pctl->mutex); dev_info(rza1_pctl->dev, "Unable to parse function and group %s\n",