From patchwork Wed Jan 23 14:15:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1029972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="uGpUQW0t"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43l6m25h8gz9s7h for ; Thu, 24 Jan 2019 01:16:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727291AbfAWOQa (ORCPT ); Wed, 23 Jan 2019 09:16:30 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51328 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbfAWOPx (ORCPT ); Wed, 23 Jan 2019 09:15:53 -0500 Received: by mail-wm1-f65.google.com with SMTP id b11so2146088wmj.1 for ; Wed, 23 Jan 2019 06:15:50 -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=lxsbnWY+u5ZD2HJ8Gj47byZdwyvd+a73Kv/KMI9VfHI=; b=uGpUQW0tYNkDz+t0BNndB2i4PWinvJadgy4277/VcnjfkcKOPd0x1RHrgZmGGSARqw 46JYT5OZuBBtwAtC1sSC3z/zd0M8imvbEzgnZtiULEOEs29HzpR8dQCSrqtSzkfm78zA pv+aMeXt+cbvFJMEkBE/74ovNGGiQ2B9VQwZ68DOyl4oH6CwsPgpz9ky5KrW4SNecILv qjZlAvaFvLTXw2RwwSSjqCsBqz3cuIrMQeIYMxwJEINgjB26nPIsdOk3J9LfC6N3A3Pa MWujK8tYZWAlhHvMzM5q53MeO6rEIcSGSdqVncCdU8DuKHPXAw2DHTB+VbqRJBiZYThm 5LhA== 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=lxsbnWY+u5ZD2HJ8Gj47byZdwyvd+a73Kv/KMI9VfHI=; b=eSgZro2JtD3nEiwPygFHoNGhp5mCWBkpCN5fYAZ5zcrDzE+nDFkktKx5ah/aEZDwx3 b894Woc0/qENrzh0pF57W58vDdTundkK5MH/Lc1RT5BwF7ejLPYlBN13ua2ginPezhDX nmhVlCYqAQV5RcZGgohh2zQf7HgO6wKCMpyyWYfiMTzVwicXzHtijZ2ngunesl+GI7Kb nEKT3MnaapqsuMC0QeyRJHab2qGUVxBs9tJp6cvFe1Lv0Wa1VMDAd3UWi85W50gJ3WUJ hUh8aZNbpv9pqFG7GzOs+LXGyiMQzARNcAGXM9pwstmmcwh4idCktD4ZyaDHl6Bjr9RJ OIZw== X-Gm-Message-State: AJcUukccnqI9ESf2a4K91kpPbXnmhbwjepFMo3YUN69QzBKwXJfGUleo sCcGJI9Rn/YY6NMZDqxff7w7nQ== X-Google-Smtp-Source: ALg8bN4OXc8aT70YhNURo9o0CEY4ZRYfzv2KtxkGiyevA9M6RVXjnot5ZG4nSh2jdvcv4AiBV7zvhw== X-Received: by 2002:a1c:b456:: with SMTP id d83mr3035253wmf.115.1548252950171; Wed, 23 Jan 2019 06:15:50 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id a8sm29072997wme.23.2019.01.23.06.15.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 06:15:49 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/9] gpio: mockup: add locking Date: Wed, 23 Jan 2019 15:15:33 +0100 Message-Id: <20190123141538.29408-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190123141538.29408-1-brgl@bgdev.pl> References: <20190123141538.29408-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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;