Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4410224imu; Tue, 29 Jan 2019 00:45:14 -0800 (PST) X-Google-Smtp-Source: ALg8bN6TAZ7bd45YlK9GtkSAd4QaARF2YRIjXRRzFwX6s4y9JyQYQ63LPGRK6xb3oZ2q0mb2dvyq X-Received: by 2002:a62:8986:: with SMTP id n6mr15954897pfk.161.1548751514449; Tue, 29 Jan 2019 00:45:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548751514; cv=none; d=google.com; s=arc-20160816; b=aEH1SWDVWJekl4KnEq7IDlxnMDhBxYnAufoZcmmYH4taewkBqc277oSO1wzNj+DKn3 7AlM2OlkqcSnwmap/nZxxDAVoRQld4RYByCfJMItsuD07+7fuGqf/UX/N9dIHQ3mZcDy 0zHdX0wwGGVkEADeQ8S9HBIqBWZTrATS2OQ7yiYJxSuODWgy+0R2Oj6fgw7sFPIYJDem RrA2sWY/KrvD923n4N0hKSDCYVJr4nTCZEFFYuonXuvMnekLJzvyV36nXoqX3SnrMNcT 42mJCXTxfW0wihW841+nhNgfCjAGXkQlwjg51iezeM2PVdW8Wp4OCTSZ0Q6PDg5MpV68 uaYA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xh6JAmkBnBKkEOMZQs9o929ceuBTII37rCxqn/4TinI=; b=zIZmQQYeBA20/88bQpfntqo32rtK5p3+3jLuEzMSjETtQWm1kOyv0GZtfZjJ6ZnorY xIHDGVJshTLEVOEuBdidKQ6qIX2DDKxE3ij7XeFqYf8VG2thoFy3+E7aeD3Aq+GEWGkP XbWkNN5b5q9nPd0JoUL6gINLHdBcTHHfFFayORxU6/rSsq8KvmwYUhY3At4bb8kPxH+s rcBwHKfF8UpLlqdPLkbBo4maeCW4hSXjNPu+A4H004m82BkIvcmR4JfzYUaleVvrrRod CJqPMRXyHTQl4weGZOi3EMwhmTY4Il0fcSF5avKUK2dtA9L2PAniPCBdx6fO71e91A75 r/Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="ltJWi/rZ"; 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 f63si23018613pfg.136.2019.01.29.00.44.58; Tue, 29 Jan 2019 00:45:14 -0800 (PST) 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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="ltJWi/rZ"; 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 S1727989AbfA2Io1 (ORCPT + 99 others); Tue, 29 Jan 2019 03:44:27 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39635 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbfA2IoZ (ORCPT ); Tue, 29 Jan 2019 03:44:25 -0500 Received: by mail-wm1-f66.google.com with SMTP id y8so16697369wmi.4 for ; Tue, 29 Jan 2019 00:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xh6JAmkBnBKkEOMZQs9o929ceuBTII37rCxqn/4TinI=; b=ltJWi/rZsnURDFa+IEr8utG5+hqmxoQ5Dfe6jZ8tlr8Yj/JCkzIsaV9okuhDKjEcBz clcdm3VwumIICl5P7Nz0BAGnEihG7kf+j/7wYX43+9ZMorSAoz0sL11JBMnqkFiPnPXD hjMj/niUOLDhRhFhTrGv8Mr34rKY3BQNnSh+5pULYUYuUReZ2Qv2fw7N/UecYrtx8TU2 2AviEK0qQNhqb+tJhjfP9GBLLqt0ax7/0+IO5ND6lg5kaRXPKpyU3D+goL+gjfnHIeNl yOH6VoDAWWaHnP3g29IkfLATNU+w8N5/DcbmojdtvtM2bA906nnWNbq7yOLQcbbsBHcj PEbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xh6JAmkBnBKkEOMZQs9o929ceuBTII37rCxqn/4TinI=; b=GH+p5+Nzkc/wYXZR7XykhVuplmZl27c12co/1+JBkDLCRHGgyFRzdEIzhpVhKL2L6W QvFLM4cWDOrihgRAW91p8Yfi36eJ4rUaNl4raZ/hKVla9WHDJburfAv/ZVhDwihu+HPf 2AuuOg+a7dI+4u+dP1sdfpu3A0XeoTCon/tlu5i32rrcyWJ6zkp2TCv7549KH+8s1c3u gvQDL/Sb8+togczkML2etgilq1NY4DfklTMIUMefqhlq60QISnwtsGjS8P/9fPvxQXGa /oWgtIaKrsJRrI5mmDE9O8W+pVggpa5HdsK9aB2m6gxzp4ytLZilxSzik5mI0CaYMBZz MTLg== X-Gm-Message-State: AJcUukc3pjSMA99YgCnN5YF1j6WPMlLahfr+Gc0cZ712fata3seUzdtR Wbaw8gCntjI6spmLZHxhAw0H6Q== X-Received: by 2002:a1c:544f:: with SMTP id p15mr20303242wmi.37.1548751463054; Tue, 29 Jan 2019 00:44:23 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:22 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 4/9] gpio: mockup: add locking Date: Tue, 29 Jan 2019 09:44:06 +0100 Message-Id: <20190129084411.30495-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> 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: Bartosz Golaszewski While no user reported any race condition problems with gpio-mockup, let's be on the safe side and use a mutex when performing any changes on the dummy chip structures. Suggested-by: Uwe Kleine-König Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 6a50f9f59c90..b4c1de6acf74 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -54,6 +54,7 @@ struct gpio_mockup_chip { struct gpio_mockup_line_status *lines; struct irq_sim irqsim; struct dentry *dbg_dir; + struct mutex lock; }; struct gpio_mockup_dbgfs_private { @@ -82,29 +83,53 @@ static int gpio_mockup_range_ngpio(unsigned int index) return gpio_mockup_ranges[index * 2 + 1]; } -static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +static int __gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); return chip->lines[offset].value; } -static void gpio_mockup_set(struct gpio_chip *gc, - unsigned int offset, int value) +static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + int val; + + mutex_lock(&chip->lock); + val = __gpio_mockup_get(gc, offset); + mutex_unlock(&chip->lock); + + return val; +} + +static void __gpio_mockup_set(struct gpio_chip *gc, + unsigned int offset, int value) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); chip->lines[offset].value = !!value; } +static void gpio_mockup_set(struct gpio_chip *gc, + unsigned int offset, int value) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + + mutex_lock(&chip->lock); + __gpio_mockup_set(gc, offset, value); + mutex_unlock(&chip->lock); +} + static void gpio_mockup_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); unsigned int bit; + mutex_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) - gpio_mockup_set(gc, bit, test_bit(bit, bits)); - + __gpio_mockup_set(gc, bit, test_bit(bit, bits)); + mutex_unlock(&chip->lock); } static int gpio_mockup_dirout(struct gpio_chip *gc, @@ -112,8 +137,10 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - gpio_mockup_set(gc, offset, value); + mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; + __gpio_mockup_set(gc, offset, value); + mutex_unlock(&chip->lock); return 0; } @@ -122,7 +149,9 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_IN; + mutex_unlock(&chip->lock); return 0; } @@ -130,8 +159,13 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + int direction; - return !chip->lines[offset].dir; + mutex_lock(&chip->lock); + direction = !chip->lines[offset].dir; + mutex_unlock(&chip->lock); + + return direction; } static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) @@ -283,6 +317,8 @@ static int gpio_mockup_probe(struct platform_device *pdev) return -ENOMEM; } + mutex_init(&chip->lock); + gc = &chip->gc; gc->base = base; gc->ngpio = ngpio; -- 2.19.1