From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A253DC0015E for ; Tue, 18 Jul 2023 13:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231608AbjGRN4f (ORCPT ); Tue, 18 Jul 2023 09:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbjGRN4c (ORCPT ); Tue, 18 Jul 2023 09:56:32 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C4391712 for ; Tue, 18 Jul 2023 06:56:11 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qLlBQ-0008CI-03; Tue, 18 Jul 2023 13:56:08 +0000 Date: Tue, 18 Jul 2023 14:55:57 +0100 From: Daniel Golle To: Miquel Raynal , Greg Kroah-Hartman , Srinivas Kandagatla , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] nvmem: core: append offset to cell name in sysfs Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The device tree node names are not required to be unique. Append the offset to the name to make cell nodes with identical names become accessible via sysfs and avoid kernel stackdump caused by sysfs: cannot create duplicate filename '...' Fixes: 757f8b3835c9 ("nvmem: core: Expose cells through sysfs") Signed-off-by: Daniel Golle --- drivers/nvmem/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 70e951088826d..90fe9dc30f8ba 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -480,7 +480,9 @@ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem) /* Initialize each attribute to take the name and size of the cell */ list_for_each_entry(entry, &nvmem->cells, node) { sysfs_bin_attr_init(&attrs[i]); - attrs[i].attr.name = devm_kstrdup(&nvmem->dev, entry->name, GFP_KERNEL); + attrs[i].attr.name = devm_kasprintf(&nvmem->dev, GFP_KERNEL, + "%s@%d", entry->name, + entry->offset); attrs[i].attr.mode = 0444; attrs[i].size = entry->bytes; attrs[i].read = &nvmem_cell_attr_read; -- 2.41.0