Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3605926imm; Wed, 5 Sep 2018 03:01:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYdXX4MP7IzWesruxxvMbnXQ2eb/YcIfNMcZ7QBhy7ukkgzeAGXb2JDAysodF5IXpiA8sIb X-Received: by 2002:a63:3f45:: with SMTP id m66-v6mr35793563pga.51.1536141675764; Wed, 05 Sep 2018 03:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536141675; cv=none; d=google.com; s=arc-20160816; b=oOUv4g4Z8Q1H2BwJfsqbiG4Vd8rmcz8Qle4npdCYi5M8aPi/vR1LcQP6INjzuBNbXV H5BtC9MNeYf4PiNVDyZAUEM8sjY1B5x2GYNGHPKAvKgsxTItLpGtw34bCozdehvWfpWT NxPC2OkLkIefiB+w+F9mJ0BUzt9WtmcS+tCqFw7XNYo/LOiIV8EESsuHVJ9DjUh9BAZu +oBtNequUqK6XtTxnxEJYPKTL0X29RjCC/QN39SsAP+COZKd0isxdD57mb1SFvmyjP7l ZGGbMwcFQTZP1DYmP1qlc7/XcjBgFB1EXrG6Sc/+2cKmacKAQA7DjUXPBGM3KcvBN3dj 99vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=OkoqiLjbJSODXJoiTP2mWCeOVuHWiRrCaV2oGASjKkw=; b=A+oSfqRzH3dMWckanRCgO1hOgNooxF2G65XPTes5fkx1xDaiWjuVTt1hkx6jQ07u8F ZsaETaHBN6cthZJ1E/pDNnqhKFufsFMl2vaanNKi4YJ0AZb06TsIwqq7H3ho4SpYhcB+ Rh4AE1znT492A7we0OuVbc5sAMbEKJIIuGEIljbzHJ26BhJ7wBiF0Mff7qTHxUf/xZVw NJ4HwCml+lwB7ji3Ufvdv+dw4EQvYvgnGKOsJFRymzIL1FzK/tukPlmbkw9C1wqxs7uK altZ/qJzde/avbEaDtNN2XaoHakdy8I9tfudPw9lcaMbx2EeGYgrioV9AmCX7M8KLdb2 e6EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=oO+MooOI; 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 d35-v6si1440437pla.116.2018.09.05.03.01.00; Wed, 05 Sep 2018 03:01:15 -0700 (PDT) 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=oO+MooOI; 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 S1728203AbeIEO1g (ORCPT + 99 others); Wed, 5 Sep 2018 10:27:36 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33976 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728114AbeIEO1f (ORCPT ); Wed, 5 Sep 2018 10:27:35 -0400 Received: by mail-wr1-f66.google.com with SMTP id g33-v6so6998663wrd.1 for ; Wed, 05 Sep 2018 02:58:07 -0700 (PDT) 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; bh=OkoqiLjbJSODXJoiTP2mWCeOVuHWiRrCaV2oGASjKkw=; b=oO+MooOIqNoUEuBIrePFnK6OJR5c/sBLGef0RbivSEySPKXncBhcnCLBmvXcUy2Ly3 9TJNH20HeBHKqT/x3ZXHhjebTFajBeHZfXVcz9tG4IySKG+BcadumSTEgvqJhMOUEGCj 6ULz9kX+pKK0osh+aDk4IyoJtgDuustMTkCW4SO2sEwd4ebY6LADDahvMAQ6qHLir0KU 6Wza8XluLjqangrGgsTfoxoOYDAQu3z7PQzXTnDYla6kgJAuwE7gpgg7Xr/q7BGWQhz5 /XtYedxnaGQ+F232vQRJ4iFooi4ihBo3PXb9zGQ18fNnfzHKR0zpeQkLQHe2m95WhF3S Cstg== 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; bh=OkoqiLjbJSODXJoiTP2mWCeOVuHWiRrCaV2oGASjKkw=; b=gb0W6CTwFITyXmDcNP4pUp4Q+rXV0pfv4Aeq3rOUDdSNqdt/vATtVsWEAfOZDu6JJE c+M1ZXQjdtvvPZvC06p9OW/S73hoBjtfTYRreMOZpzLgdJRhgHmTN+ynI3aP+87g9amz ugTyG5l/m5kmMlN3mPuZWvKoGIuVy/9TuL98eZRgLF97ZgdbbwlbznH/S6zes4tj5sqG WO4DTSk1/lQe6K2x3uaKRw5rb2HNNEnRvdumEb886FfgPPnItlk1ZqIpQjtIsePYuHhx f4L//pTFN8v2EuteUeWnyj6TWWDraFzWpKcjnMhoNCfwMjdDfEqXrxn4Lzwk+UvvSLLg nBYQ== X-Gm-Message-State: APzg51AbIs7RCUIOUixWmw6nsUz9sDPkMf01WW8QnlFAxK/R/uIf6yNC 1ELpdyBoCmEmziv7UV6wSxHZjw== X-Received: by 2002:adf:e792:: with SMTP id n18-v6mr14381020wrm.136.1536141486499; Wed, 05 Sep 2018 02:58:06 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-33-235.w90-86.abo.wanadoo.fr. [90.86.152.235]) by smtp.gmail.com with ESMTPSA id l12-v6sm2127815wrv.29.2018.09.05.02.58.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Sep 2018 02:58:05 -0700 (PDT) From: Bartosz Golaszewski To: Srinivas Kandagatla , Joachim Eastwood , "David S . Miller" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Andrew Morton , Arnd Bergmann , Jonathan Corbet , Sekhar Nori , Kevin Hilman , David Lechner , Boris Brezillon , Andrew Lunn , Alban Bedel , Maxime Ripard Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski Subject: [PATCH 02/13] nvmem: remove the global cell list Date: Wed, 5 Sep 2018 11:57:27 +0200 Message-Id: <20180905095738.26406-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180905095738.26406-1-brgl@bgdev.pl> References: <20180905095738.26406-1-brgl@bgdev.pl> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Make each nvmem device the owner of its nvmem cells. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index bb475c2688f9..86af62e2df47 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -38,6 +38,7 @@ struct nvmem_device { int flags; struct bin_attribute eeprom; struct device *base_dev; + struct list_head cells; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; void *priv; @@ -58,9 +59,6 @@ struct nvmem_cell { static DEFINE_MUTEX(nvmem_mutex); static DEFINE_IDA(nvmem_ida); -static LIST_HEAD(nvmem_cells); -static DEFINE_MUTEX(nvmem_cells_mutex); - #ifdef CONFIG_DEBUG_LOCK_ALLOC static struct lock_class_key eeprom_lock_key; #endif @@ -284,29 +282,25 @@ static struct nvmem_device *of_nvmem_find(struct device_node *nvmem_np) static void nvmem_cell_drop(struct nvmem_cell *cell) { - mutex_lock(&nvmem_cells_mutex); + mutex_lock(&nvmem_mutex); list_del(&cell->node); - mutex_unlock(&nvmem_cells_mutex); + mutex_unlock(&nvmem_mutex); kfree(cell); } -static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem) +static void nvmem_device_remove_all_cells(struct nvmem_device *nvmem) { - struct nvmem_cell *cell; - struct list_head *p, *n; + struct nvmem_cell *cell, *p; - list_for_each_safe(p, n, &nvmem_cells) { - cell = list_entry(p, struct nvmem_cell, node); - if (cell->nvmem == nvmem) - nvmem_cell_drop(cell); - } + list_for_each_entry_safe(cell, p, &nvmem->cells, node) + nvmem_cell_drop(cell); } static void nvmem_cell_add(struct nvmem_cell *cell) { - mutex_lock(&nvmem_cells_mutex); - list_add_tail(&cell->node, &nvmem_cells); - mutex_unlock(&nvmem_cells_mutex); + mutex_lock(&nvmem_mutex); + list_add_tail(&cell->node, &cell->nvmem->cells); + mutex_unlock(&nvmem_mutex); } /* @@ -423,6 +417,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) goto err_device_del; } + INIT_LIST_HEAD(&nvmem->cells); + return nvmem; err_device_del: -- 2.18.0