From patchwork Fri Sep 16 16:02:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 76406 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp570513qgf; Fri, 16 Sep 2016 09:03:24 -0700 (PDT) X-Received: by 10.98.39.193 with SMTP id n184mr24298341pfn.164.1474041804056; Fri, 16 Sep 2016 09:03:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a73si7886530pfc.20.2016.09.16.09.03.23; Fri, 16 Sep 2016 09:03:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964932AbcIPQDQ (ORCPT + 1 other); Fri, 16 Sep 2016 12:03:16 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:36921 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964933AbcIPQDG (ORCPT ); Fri, 16 Sep 2016 12:03:06 -0400 Received: by mail-wm0-f46.google.com with SMTP id k186so49854998wmd.0 for ; Fri, 16 Sep 2016 09:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VeJzvwV7X1stOx9SDeLqwC1asEuv2n6FwowQ9VgkKTs=; b=HefGrlEwetTUcqRQzUpVJ9dp8HBveh4pqotAFe+dkfmmxApXiRC8APeHqsZZR7GK3o 8LwLwN7icyhCVd3RRjyG5cw4T6dF/KU8IFhMa/uVSXQURu5gdXBJsqNmYc8HED/VUWB9 i7EiAVodR1Svk+I8qOU3fSqH753+LiXyk44jy4/dMCPlZ6O5obxsds/IjLFdri2KnxPH hwcprOy+QCg/U6n4BhQ5PnyJjujExohxaQ6f8+phW9aUkeryVjZ7Y3IlkzKIrIIf9ah8 tvtgCxXSFGwKKrmluqzoe1bSKyz7GUuGbZ19rtAx4dtTutpQ9Wk940riMub52hmkj++x LHuw== 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=VeJzvwV7X1stOx9SDeLqwC1asEuv2n6FwowQ9VgkKTs=; b=XlwvKX228D9WDc40HxdaVhqL+sEnji4hkXUxk9N3EciLKaTkuP/p0sttujYAnePnB0 8D1usljXusAVJFSymG7xM+WOmGGmJiNJnawcF4STd3HVH6B8IU5ZREwNXNEg7maV/124 7D3V9TT80OGxpwl9TrPeY6jz76tMCBjWJA1ftUt9HFIGCUOsP+7VVvZ/1I7Inl+JA32G 2aGy9KO0Zjo5QOmZaiMhELN2gsHQ7gzevbQUMhbtLOET6mYvon8EfbDGNkCEo8zjDSPR 6eWDfZb9ob3dEfbJs3q6fUpAGPBPxoAhmwj2OJhPaBuc08Y+EZFp273L+RKh0/8I3GTO yGsQ== X-Gm-Message-State: AE9vXwP2ng/q4+d8XPQ5wR4qELzYnAMrV47yySnPhNBcHxNpH6BzSBk8A6GRk00MBhe9Amhi X-Received: by 10.28.28.70 with SMTP id c67mr8389517wmc.8.1474041785163; Fri, 16 Sep 2016 09:03:05 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id ub8sm9033421wjc.39.2016.09.16.09.03.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Sep 2016 09:03:04 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Andy Shevchenko , Vignesh R , Yong Li , Geert Uytterhoeven , Peter Zijlstra , Ingo Molnar , Wolfram Sang , Peter Rosin Cc: linux-i2c , linux-gpio , LKML , Bartosz Golaszewski Subject: [PATCH v2 4/4] gpio: pca953x: fix an incorrect lockdep warning Date: Fri, 16 Sep 2016 18:02:45 +0200 Message-Id: <1474041765-17818-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1474041765-17818-1-git-send-email-bgolaszewski@baylibre.com> References: <1474041765-17818-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org If an I2C GPIO multiplexer is driven by a GPIO provided by an expander when there's a second expander using the same device driver on one of the I2C bus segments, lockdep prints a deadlock warning when trying to set the direction or the value of the GPIOs provided by the second expander. The below diagram presents the setup: - - - - - ------- --------- Bus segment 1 | | | | | |--------------- Devices | | SCL/SDA | | | | | Linux |-----------| I2C MUX | - - - - - | | | | | Bus segment 2 | | | | |------------------- ------- | --------- | | | - - - - - ------------ | MUX GPIO | | | | | Devices | GPIO | | | | | Expander 1 |---- - - - - - | | | ------------ | SCL/SDA | ------------ | | | GPIO | | Expander 2 | | | ------------ The reason for lockdep warning is that we take the chip->i2c_lock in pca953x_gpio_set_value() or pca953x_gpio_direction_output() and then come right back to pca953x_gpio_set_value() when the GPIO mux kicks in. The locks actually protect different expanders, but for lockdep both are of the same class, so it says: Possible unsafe locking scenario: CPU0 ---- lock(&chip->i2c_lock); lock(&chip->i2c_lock); *** DEADLOCK *** May be due to missing lock nesting notation In order to get rid of the warning, retrieve the adapter nesting depth and use it as lockdep subclass for chip->i2c_lock. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-pca953x.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Acked-by: Linus Walleij diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 02f2a56..892dc04 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -786,6 +786,8 @@ static int pca953x_probe(struct i2c_client *client, chip->chip_type = PCA_CHIP_TYPE(chip->driver_data); mutex_init(&chip->i2c_lock); + lockdep_set_subclass(&chip->i2c_lock, + i2c_adapter_depth(client->adapter)); /* initialize cached registers from their original values. * we can't share this chip with another i2c master.