From patchwork Sat Dec 20 22:34:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 5523361 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C8BD59F326 for ; Sat, 20 Dec 2014 22:35:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E691020165 for ; Sat, 20 Dec 2014 22:35:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 12C7820166 for ; Sat, 20 Dec 2014 22:35:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbaLTWfa (ORCPT ); Sat, 20 Dec 2014 17:35:30 -0500 Received: from mail.kapsi.fi ([217.30.184.167]:58873 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752572AbaLTWfa (ORCPT ); Sat, 20 Dec 2014 17:35:30 -0500 Received: from dyn3-82-128-190-202.psoas.suomi.net ([82.128.190.202] helo=localhost.localdomain.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1Y2ScS-0008TP-27; Sun, 21 Dec 2014 00:35:28 +0200 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Antti Palosaari , Lars-Peter Clausen , Mark Brown Subject: [PATCHv2 1/2] regmap: add configurable lock class key for lockdep Date: Sun, 21 Dec 2014 00:34:51 +0200 Message-Id: <1419114892-4550-1-git-send-email-crope@iki.fi> X-Mailer: git-send-email 2.1.0 X-SA-Exim-Connect-IP: 82.128.190.202 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 Lockdep validator complains recursive locking and deadlock when two different regmap instances are called in a nested order, as regmap groups locks by default. That happens easily for example when both I2C client and I2C adapter are using regmap. As a solution, add configuration option to pass custom lock class key for lockdep validator. Here is example schema, where nested regmap calls are issued, when more than 1 block uses regmap. __________ ___________ ___________ | USB IF | | demod | | tuner | |----------| |-----------| |-----------| | |--I2C--|-----/ ----|--I2C--| | |I2C master| | I2C mux | | I2C slave | |__________| |___________| |___________| Cc: Lars-Peter Clausen Cc: Mark Brown Signed-off-by: Antti Palosaari --- drivers/base/regmap/regmap.c | 3 +++ include/linux/regmap.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index d2f8a81..56064d3 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -559,6 +559,9 @@ struct regmap *regmap_init(struct device *dev, mutex_init(&map->mutex); map->lock = regmap_lock_mutex; map->unlock = regmap_unlock_mutex; + if (config->lockdep_lock_class_key) + lockdep_set_class(&map->mutex, + config->lockdep_lock_class_key); } map->lock_arg = map; } diff --git a/include/linux/regmap.h b/include/linux/regmap.h index c5ed83f..f930370 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -134,6 +134,10 @@ typedef void (*regmap_unlock)(void *); * @lock_arg: this field is passed as the only argument of lock/unlock * functions (ignored in case regular lock/unlock functions * are not overridden). + * @lock_class_key: Custom lock class key for lockdep validator. Use that when + * regmap in question is used for bus master IO in order to avoid + * false lockdep nested locking warning. Valid only when regmap + * default mutex locking is used. * @reg_read: Optional callback that if filled will be used to perform * all the reads from the registers. Should only be provided for * devices whose read operation cannot be represented as a simple @@ -197,6 +201,7 @@ struct regmap_config { regmap_lock lock; regmap_unlock unlock; void *lock_arg; + struct lock_class_key *lockdep_lock_class_key; int (*reg_read)(void *context, unsigned int reg, unsigned int *val); int (*reg_write)(void *context, unsigned int reg, unsigned int val);