From patchwork Tue Nov 6 15:41:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 150278 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4041315ljp; Tue, 6 Nov 2018 07:43:51 -0800 (PST) X-Google-Smtp-Source: AJdET5c6pM35hN4oE/f1BzheQILyK2ykWCP9uEQniFiOtI2wfyfuEM4lNPVLIIELl3HTs6IbnJEx X-Received: by 2002:a17:902:9346:: with SMTP id g6-v6mr22678838plp.148.1541519031479; Tue, 06 Nov 2018 07:43:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541519031; cv=none; d=google.com; s=arc-20160816; b=FvHu5T5bhKJFF2LP+H9mn2pssVTluHYVyxhGkauJR0qRCUucTppgkN0gx3HsknUsbG sajgOkEhWepEA9ltyWy1HngVCMa/bcnhEsjO5Bx8fjHgkBK2lCC8Kcvlvaa8ywc0SQWG h1swSFwuD1/z7q0Q/E5rttzrO+sdssaOWIN8JwTujTeTuCX5F5GvncxjDhNFFhFjEkGG paNuyutWJzAeXyF5wx8VLjUNMIEWxRtNFCqd74kbhAjxdBlPFKnd/mpDHCw0RbNSzUHb tSlzJy6oUrP5wsRDI2K64Kg9ifer/yXFq3fP9hs6xwHi/KJvECKf2oNRa6xEsVtIF0hl YNpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NyNQOO6YaDrbBzaN4x2sXwLMUP+wh63KFQ8W6ySoA48=; b=vPnMpsn3ajggcULLvP+3VfRVvsAPswYHG6o/XbPTyQ/ji9f0rkUxaMBiLVuCTq2ILd uRp5g+IPYKKugV9KYmFVcIRrKRL+vmQORE2MwVjRlPBGR1op8wgTNzSyE9dzX0OyRl1h CVtQuidSBvG4KVEtyR3cpTPh2LJMpth1UMLRCr4NRe53X7tVAeDZf+nSIGfjiNSp65EW xlO4pvUvNYj/RZurYZ9OU3QTuXYDGxq4TB2GeZiN8bYqHU52ZDyK7FD1u/oSrzhtZVXU yIH2tB2kLD9anc0Sc6HloiRGOv8P4LlCYDMu9iriGmpYIRvlKOm7z8PROmjm7ZfcL3fx ZPvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X3BKmtCg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3-v6si46066667pgh.250.2018.11.06.07.43.51; Tue, 06 Nov 2018 07:43:51 -0800 (PST) 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=@linaro.org header.s=google header.b=X3BKmtCg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388755AbeKGBJf (ORCPT + 32 others); Tue, 6 Nov 2018 20:09:35 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35132 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387714AbeKGBJf (ORCPT ); Tue, 6 Nov 2018 20:09:35 -0500 Received: by mail-wr1-f65.google.com with SMTP id z16-v6so14061404wrv.2 for ; Tue, 06 Nov 2018 07:43:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=NyNQOO6YaDrbBzaN4x2sXwLMUP+wh63KFQ8W6ySoA48=; b=X3BKmtCg4oCRZTcCcapDNRxAjkP1e1Bsj2OI/5VGKNnpS+mnWuPYQt8glAykMvmGMu EvQeBn06+iKIaNRGrZdn58dsSUln1gA/AYVOD1SwDWbSlKpMnVqMmjjwkn4F79exXohE s3qiCbAVjTRybfDSriJdtwLBPvhQozlBHFUB4= 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:mime-version :content-transfer-encoding; bh=NyNQOO6YaDrbBzaN4x2sXwLMUP+wh63KFQ8W6ySoA48=; b=KMN1YMv1xVONaPFqHBAP03u4fvmH+9ffA5ihKaLBXDqABZyxUmAt2aXvgmI3wa2EGh VQeEiJhnPyTcmBzbfpORP7K4sx0oU7EBfnJ+1QpvcWd3JN4x7zzeHbpKIdooSMLvh8JZ AD6cS63ZGsvcekpoDig9NqzgTxNm3SXOPPiuqCsr6EdzWyzLVCOm6Spp0OWCM0PcZGcj T4o2gT9ZNrq5ychFQtHpv1WL1oG59v4zGqMWyL2Wn4KjbkLT7CJDq8RMUhi17tgyqfl1 WQD5CMqMXboHJRNFn5KkSe5bqujIqK6uogZnQobSe4IlC0DN+gCYEJ+6sLnkr9r1+JoD eAGg== X-Gm-Message-State: AGRZ1gKgGB2D0kLkVXQpVAsLBPSxTIdjIFYMtILI2gz0PQxedodn1jG8 DcNz8uZyf4S9f1aupIv6NCdICA== X-Received: by 2002:adf:dbc3:: with SMTP id e3-v6mr25299425wrj.165.1541519026574; Tue, 06 Nov 2018 07:43:46 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id o81-v6sm1447356wmo.38.2018.11.06.07.43.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Nov 2018 07:43:45 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, niklas.cassel@linaro.org, Srinivas Kandagatla Subject: [PATCH] nvmem: core: fix regression in of_nvmem_cell_get() Date: Tue, 6 Nov 2018 15:41:41 +0000 Message-Id: <20181106154141.2260-1-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org NVMEM DT support seems to be totally broken after commit e888d445ac33 ("nvmem: resolve cells from DT at registration time") Fix this! Index used in of_nvmem_cell_get() to find cell is specific to consumer, It can not be used for searching the cell in provider. Use device_node instead of this to find the matching cell in device tree case. Fixes: e888d445ac33 ("nvmem: resolve cells from DT at registration time") Reported-by: Niklas Cassel Signed-off-by: Srinivas Kandagatla Tested-by: Niklas Cassel --- Hi Greg, Could you please take this one for next rc, as dt support seems to be broken in v4.20-rc1 Thanks, srini drivers/nvmem/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.19.1 diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9b18ce90f907..27f67dfa649d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -44,6 +44,7 @@ struct nvmem_cell { int bytes; int bit_offset; int nbits; + struct device_node *np; struct nvmem_device *nvmem; struct list_head node; }; @@ -298,6 +299,7 @@ static void nvmem_cell_drop(struct nvmem_cell *cell) mutex_lock(&nvmem_mutex); list_del(&cell->node); mutex_unlock(&nvmem_mutex); + of_node_put(cell->np); kfree(cell->name); kfree(cell); } @@ -530,6 +532,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) return -ENOMEM; cell->nvmem = nvmem; + cell->np = of_node_get(child); cell->offset = be32_to_cpup(addr++); cell->bytes = be32_to_cpup(addr); cell->name = kasprintf(GFP_KERNEL, "%pOFn", child); @@ -960,14 +963,13 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) #if IS_ENABLED(CONFIG_OF) static struct nvmem_cell * -nvmem_find_cell_by_index(struct nvmem_device *nvmem, int index) +nvmem_find_cell_by_node(struct nvmem_device *nvmem, struct device_node *np) { struct nvmem_cell *cell = NULL; - int i = 0; mutex_lock(&nvmem_mutex); list_for_each_entry(cell, &nvmem->cells, node) { - if (index == i++) + if (np == cell->np) break; } mutex_unlock(&nvmem_mutex); @@ -1011,7 +1013,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) if (IS_ERR(nvmem)) return ERR_CAST(nvmem); - cell = nvmem_find_cell_by_index(nvmem, index); + cell = nvmem_find_cell_by_node(nvmem, cell_np); if (!cell) { __nvmem_device_put(nvmem); return ERR_PTR(-ENOENT);