From patchwork Mon Oct 20 23:27:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 5108581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B65F3C11AC for ; Mon, 20 Oct 2014 23:31:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 121F420107 for ; Mon, 20 Oct 2014 23:31:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1ABE7201DD for ; Mon, 20 Oct 2014 23:31:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XgMNn-0002Mj-2x; Mon, 20 Oct 2014 23:28:59 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XgMNM-0002EV-Ot for linux-arm-kernel@lists.infradead.org; Mon, 20 Oct 2014 23:28:36 +0000 Received: by mail-pa0-f46.google.com with SMTP id fa1so68515pad.33 for ; Mon, 20 Oct 2014 16:28:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4f8iQl0z6JdL+dwELvaUpaAB11iVOz/wSBzf8T8xLc4=; b=Ay3h7dXURcjqE4MslmjQZ2cdiNKT8NsmgYboN//9uMidTBss4R4cUzmO+kBMSi43cU Oe9uytnUm3KVd/Pv6EutpXgd1kfLNEmibQD7SMMkHqzVpaUfZNt+D9Tc3gegsudKcZBS Fpp22kSksQA4+Syh8ic2AYm0EM121NjmhNGXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4f8iQl0z6JdL+dwELvaUpaAB11iVOz/wSBzf8T8xLc4=; b=SkgiHFZOE+5BrjdRD8LaIcnYnbjNke0z8EMQpOtuX8zrSn7JwtqiCE4KWVcFeDVC0q mAToO+KW696EaEokk1jrfNDlyk3h6ETppWg6IrwV69g3/NslYoqm3z+lHIchEBAEQSte 2AtSEe5AZyMuVGK1SVyESVkudQN1MHbcKCtf1zzPYybzfXcxYRSH56zzOuCF3eh4z+Ky XaHxYKCuxNAEU9L+WNYnDeyXMpr6GwYUraMSOGlswihHEMf+4d7nvefmCXVZjFbOL8Lx s0qVajtrrSi2RaEka6otb50t8K7J+GHkceEPXBfjGd4h6ccWbowQW/AvgEWeq8nnoT4w 9CJg== X-Gm-Message-State: ALoCoQkg/ulNPoJLhWTAGt2NeTS4651yy8l6/tyOx7N8ISHFx0/aG+FnmFKC0mrjuPrPlplu6P7h X-Received: by 10.66.138.47 with SMTP id qn15mr30979995pab.82.1413847691901; Mon, 20 Oct 2014 16:28:11 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.162.15]) by mx.google.com with ESMTPSA id tc5sm10080198pbc.51.2014.10.20.16.28.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 20 Oct 2014 16:28:11 -0700 (PDT) From: Doug Anderson To: Linus Walleij , Heiko Stuebner Subject: [PATCH 4/4] pinctrl: rockchip: Protect read-modify-write with the spinlock Date: Mon, 20 Oct 2014 16:27:50 -0700 Message-Id: <1413847670-12245-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1413847670-12245-1-git-send-email-dianders@chromium.org> References: <1413847670-12245-1-git-send-email-dianders@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141020_162832_865022_2B6296DC X-CRM114-Status: GOOD ( 12.95 ) X-Spam-Score: -0.8 (/) Cc: Doug Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Chris Zhong , Sonny Rao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There were a few instances where the rockchip pinctrl driver would do read-modify-write with no spinlock. Add a spinlock for these cases. Signed-off-by: Doug Anderson --- drivers/pinctrl/pinctrl-rockchip.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index 14a5683..669e5e8 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -871,6 +871,8 @@ static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *gc, if (ret < 0) return ret; + spin_lock_irqsave(&bank->slock, flags); + data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); /* set bit to 1 for output, 0 for input */ if (!input) @@ -879,6 +881,8 @@ static int _rockchip_pmx_gpio_set_direction(struct gpio_chip *gc, data &= ~BIT(pin); writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR); + spin_unlock_irqrestore(&bank->slock, flags); + return 0; } @@ -1395,6 +1399,7 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc) u32 polarity = 0, data = 0; u32 pend; bool edge_changed = false; + unsigned long flags; dev_dbg(bank->drvdata->dev, "got irq for bank %s\n", bank->name); @@ -1440,10 +1445,14 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc) if (bank->toggle_edge_mode && edge_changed) { /* Interrupt params should only be set with ints disabled */ + spin_lock_irqsave(&bank->slock, flags); + data = readl_relaxed(bank->reg_base + GPIO_INTEN); writel_relaxed(0, bank->reg_base + GPIO_INTEN); writel(polarity, bank->reg_base + GPIO_INT_POLARITY); writel(data, bank->reg_base + GPIO_INTEN); + + spin_unlock_irqrestore(&bank->slock, flags); } chained_irq_exit(chip, desc); @@ -1457,6 +1466,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) u32 polarity; u32 level; u32 data; + unsigned long flags; int ret; /* make sure the pin is configured as gpio input */ @@ -1464,15 +1474,20 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) if (ret < 0) return ret; + spin_lock_irqsave(&bank->slock, flags); + data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); data &= ~mask; writel_relaxed(data, bank->reg_base + GPIO_SWPORT_DDR); + spin_unlock_irqrestore(&bank->slock, flags); + if (type & IRQ_TYPE_EDGE_BOTH) __irq_set_handler_locked(d->irq, handle_edge_irq); else __irq_set_handler_locked(d->irq, handle_level_irq); + spin_lock_irqsave(&bank->slock, flags); irq_gc_lock(gc); level = readl_relaxed(gc->reg_base + GPIO_INTTYPE_LEVEL); @@ -1522,6 +1537,7 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) writel_relaxed(polarity, gc->reg_base + GPIO_INT_POLARITY); irq_gc_unlock(gc); + spin_unlock_irqrestore(&bank->slock, flags); return 0; }