Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1605465imm; Fri, 7 Sep 2018 03:12:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYvtB9UohqV/mIm3M+7juNNc25Gum5PdftcLORzDWi2vnQUwfUJyejB8cfdw/D3aldS9uKA X-Received: by 2002:aa7:8087:: with SMTP id v7-v6mr7688629pff.38.1536315145271; Fri, 07 Sep 2018 03:12:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536315145; cv=none; d=google.com; s=arc-20160816; b=tGgyXjiTvH8g9YuL0MyHwv6s2sFq3V3JUJMlM2a0q5wNN5J702rW04bMK88Pj/a+h0 TV6/Bjt1VJWzVpBihe4x4ZZtP/u5XvVDHGdvA1K2ktuS0R0RK2D8DoR+5tvag694jEcl ZsIud3XliQqIZYun4KTFkIUKr1baIJ2a6b/K9bA1X4rQGAAhFjJkf/PFlmuhAGpqIXA5 Bb5eZM5quspJ/ydsLrquO/iue+9Sfw9LOvHJje5S/GZNo7/0/u8Wn0RbB3Vpu+REkGmW scljhz+5YmuLOxDl7CTnrDFNiOUAGg3XzTQqT20KA6bvwJTPBB6UHHGgyyTZItAAIHmK J2Jw== 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=bhy2oWZ9Wjnmauma2pQRXLL2EsT2dVyBe+hsi7ezHuiLRvo9k0/tnPqMn/rndv8Jjt a9pKAXa7CVNrCsIF5LydhzU37qpD0kppOqV4+6Ro2iFvREbkBW4RepCENARvFcY+ivyT kc3AaX0r+pXTdRsfeBZvBcVa3lSHthZdUaqNdlpik6gQm6Ct7zhZW84uK8BKsvyY4USo dDIq+6GdMGRow6cAHlu6RyqOv3UD7V7+PMt0ZyV6svb0SZjMonG2lpedUkaGr8AOLPEV HkIuEqDkYSfArTvugtUlvxjenuQQaJh3FaVxQnx9a89uIrWd+C5BqXWBLnzVQY+BmDS3 GdHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="Ql67q/cv"; 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 e20-v6si8159515pgm.172.2018.09.07.03.12.10; Fri, 07 Sep 2018 03:12:25 -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="Ql67q/cv"; 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 S1728428AbeIGOsg (ORCPT + 99 others); Fri, 7 Sep 2018 10:48:36 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39521 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbeIGOsf (ORCPT ); Fri, 7 Sep 2018 10:48:35 -0400 Received: by mail-wr1-f66.google.com with SMTP id s14-v6so5399278wrw.6 for ; Fri, 07 Sep 2018 03:08:21 -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=Ql67q/cvaDNfqNAJLZ2meBMvoRpSakM4XzL+fx23NO9k4x8rlyCD9s3n5YGDwet4/2 iwdk4tqwtt4FCURfcLMyJFJwG6Q6kvQ+uOtEiaLai1wldC8Ulu6OmBujeN93eoKQ1z+B K/jBklhrhuywVD6BztEtZjiZOWTwXjp/RfJhrtWWbgmLZ504+93EKiyBW990DdHipuKA ZpJy0tvsvkVk4IX+7MpqkklIA7YmQ5JPfmtiZfNnkbubr9fH1w+vUe7jx/oFy/MyK1o0 eGZH0fXT1HoXSZ1HPwlUbQ/m6r9xvIq0/g1yjo72/4J1Qc5l95XljX1MV5npITdl2Gz6 yp2A== 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=jCVLSu/qnMw65VLwLG4T3zlrTWUFVhCa2dNBewGtpInrqD6YC5MT+4LN2yhR5+cqkj O8JOuHHCeLREj1TEjaMboDpB1/7ahChpZvR9UDoDmr0gdXOn9VeFRWzlPfstHcC3AJ6x C7tVYxYq5NaWbYrwqQJVgsNmAZyWIVtqeeS6E0NiEdD8AQUUtgup08Szj1Gx/9brt5Gu IIHdUdwsqMU8JRnOli3NaSfhxy66016ZJEbSx4ERxw/Y0ulz7Xk3p8aHZrQkCEB45HlE 4xWrdamzTqmBKW/y1zPwx4cP96tw/r64lGDuWB+6soKrFWhe6wW/4/XFY/Aq7ZDFDsyj jfIg== X-Gm-Message-State: APzg51CSvvExOpC+J5n9zSh0Fb9buUPuPWq11TqK3qZhH3sS0J48Rk/3 LypqKnxBLqVMBIhqeQnspfXadw== X-Received: by 2002:a5d:4a44:: with SMTP id v4-v6mr5551176wrs.278.1536314901286; Fri, 07 Sep 2018 03:08:21 -0700 (PDT) Received: from brgl-bgdev.baylibre.local (AStLambert-681-1-83-232.w90-86.abo.wanadoo.fr. [90.86.25.232]) by smtp.gmail.com with ESMTPSA id 72-v6sm6631619wrb.48.2018.09.07.03.08.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 03:08:20 -0700 (PDT) From: Bartosz Golaszewski To: Srinivas Kandagatla , "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 , Chen-Yu Tsai Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Bartosz Golaszewski Subject: [PATCH v2 02/16] nvmem: remove the global cell list Date: Fri, 7 Sep 2018 12:07:36 +0200 Message-Id: <20180907100750.14564-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907100750.14564-1-brgl@bgdev.pl> References: <20180907100750.14564-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