From patchwork Tue Oct 4 08:37:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 612213 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp26672pvb; Tue, 4 Oct 2022 01:38:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7hKpm/0lvX3jFi6sR9fcl3lRquQqpYmwaCyNJUubZCSEg977z6M+QZ9H0rgDtpgANxumQC X-Received: by 2002:a17:90b:384a:b0:20a:dbe3:25d7 with SMTP id nl10-20020a17090b384a00b0020adbe325d7mr1129104pjb.85.1664872693030; Tue, 04 Oct 2022 01:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664872693; cv=none; d=google.com; s=arc-20160816; b=Q6oCgBfH34LEYsS5c2GipE3RYR6KjSOGPlo40m5s+RkdZTdBgj2guRUYMVLgqJPcG2 lNyPljVztgYJARBbdu+F103S5DCmOhOcgF7tryJbAnyIiA3upqdZoLI8Nuy8uwvq1CzJ AKf7vNmW9mFlHHtBz60FPUcy9J5GcGigJ9U4/gQXHXuwmvExaS8R7XNT+XZhm+4yyxyi EpBTAMmQ/Xo/5igShOgYryT6dz0z9bxirHtKYkksIb0IogNOFaORgg7FaJbfYLfN0A9k PkxaDJFbYUWH531eDTqQxBZ6mRadXq8+SP93tgqe/jhQ2jeOFMB+QfIj0AWkV9L+VZV3 /eOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-signature; bh=zd9j8QiK9rBISICjMhUmGgrBdD4BcI7l9fiQpDHxq0k=; b=QUDdx2OyHupzrnFTzSPrEw2QtC1B04lNvPbicmCLItH62mPE7JJOBnl6LEs06cbzQD zQEMB8xg/tuGTdjJhts6hGXTrtti3cCKmCaALqdr5oHdgap+RP6kY0LQ77Cm+3AbzaMY OO8lU4l9vG8w4fVQf3vyrXiajKJGHVa0TTY2o4AqaXUvtzMHq94R+W3oCkg8vC7ceuXH ktQxQyKKmJKhGCYKkcTKGcv+xvHkMKPmolMgpUHWf4QWkXvMhxPDR1EJ16QCvjqHqn+p p3babxtK/3UglYbpW3kaAXLVjh5MaUvQIfeyhM2C/wzO6fPcHoul4OuNwF3XRhe35tkb pIhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20210309 header.b=49suF6Xy; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=IB39GjvK; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:3::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:3::133]) by mx.google.com with ESMTPS id c16-20020a170902d49000b0017f5c8315dbsi5794613plg.359.2022.10.04.01.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 01:38:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:3::133 as permitted sender) client-ip=2607:7c80:54:3::133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org header.s=bombadil.20210309 header.b=49suF6Xy; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=IB39GjvK; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 2607:7c80:54:3::133 as permitted sender) smtp.mailfrom="linux-mtd-bounces+patch=linaro.org@lists.infradead.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=zd9j8QiK9rBISICjMhUmGgrBdD4BcI7l9fiQpDHxq0k=; b=49suF6XyvAbM4e wOFHUyFUBOfYICJrVuPMzqVMOByqy3DRxRYdc7mELxAUntLUqMFLrgGY4u6nWunqsMXyQJrUo4m7h aUVOyk0gz1hn60ImVh1LBgf9M/u7f9gZe+xIqfhJURy45pRqXEL+bGEhN/kFR0Hc5WQsWnjCrQ7Q+ 5j5gNNYrDLWoohBCkM7zWxLE2w+Ew0Wlfp5DP4ZcxtlT4269SmwfVmHFAzocxVtkSZF0+zQniGXbF 6+ZTjg3/43MbIEHGZtQZJK2MFusdKNHdEksSDtHnhte+mx/DUdCfirazREfxTBTfAMFVEafQ1OhYY K0qEMH3Xmrj3q22fiFgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofdQa-008yQm-FI; Tue, 04 Oct 2022 08:37:24 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofdQX-008yPX-3v for linux-mtd@lists.infradead.org; Tue, 04 Oct 2022 08:37:22 +0000 Received: by mail-ed1-x529.google.com with SMTP id s2so7261666edd.2 for ; Tue, 04 Oct 2022 01:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=kShu3JiHXeOC6qlCggCXPdZVbnNPqXavY4BcrnK5Xm4=; b=IB39GjvKSpw8yqo7YB/mEkBVWTY3fslQk1Pr3I9rSGi3MTuep5N992Nuo/RDn8cQhw kOFr+GMG7/tOszPtpOvRF7TZvul0ACRc20XmqAqhp8a100tZ+Am9zvuVs7XholdFvMDB YAqYbghk+ZcAkIWWJvZ5ksCCJ4KnRYSPwP3cJFjLXkm+iEkjZWjxkb4qknzBZjByflpv m4OwglJgaocdKWdr9SmnDVxJTFI5j9+Y8ngyM4NvGuJDXaD5w09eou3VUUXQ7QYVBTLt GjxY6XWX4OMf3p4GEU+X2ZO1QLULkXCjID8MmyDBsgMA36tb/2ly5Ga3EYmXGQ2m+ZOs X6Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=kShu3JiHXeOC6qlCggCXPdZVbnNPqXavY4BcrnK5Xm4=; b=G1hDQ/WRrS6KrOlRgiLUfg5Xi+ABM/P0WTPrLhBnumGSQTNwJu8UXutE1eq45CApwg yFiHVgwc13YNsy6gVqju6035tX2ZJuVj47nProexbnbGwjPIGHhPsrYf/Dcbs3L+DSgE oew3Sn5/eIv7maeX7xaInj/VvhzXY/DUKjSmlEgi9G2yUvNYNO1BdLk0nOsCrv3YryiX nAt1x1ge88f5q0kXh1Fw5AysOa9gpz0e0yVi52cio7goleXXS3TyC7tQBkMqiwLsYWJX q3Hu3rIpHD5ipqp9aduUed2GneXaSwCjWXziITO+AZXOqLwQYD9Srq9gFCdXVMvVxLn+ CnRw== X-Gm-Message-State: ACrzQf0MMp2WxYNjkU8fc7uyGdtkZpDCLUrhs9x77uFQh+Sg2bJHBWJV RH4zeff46WZ8A4s2JjDrEF4= X-Received: by 2002:a05:6402:33c5:b0:447:e4a3:c930 with SMTP id a5-20020a05640233c500b00447e4a3c930mr22278878edc.401.1664872638877; Tue, 04 Oct 2022 01:37:18 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id kv20-20020a17090778d400b00787a6adabe9sm6598376ejc.75.2022.10.04.01.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 01:37:18 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: ansuelsmth@gmail.com, linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= Subject: [PATCH V2 1/2] mtd: core: simplify (a bit) code find partition-matching dynamic OF node Date: Tue, 4 Oct 2022 10:37:09 +0200 Message-Id: <20221004083710.27704-1-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221004_013721_182607_29F4F4EC X-CRM114-Status: GOOD ( 14.85 ) X-Spam-Score: 0.1 (/) X-Spam-Report: =?utf-8?q?Spam_detection_software=2C_running_on_the_system_?= =?utf-8?q?=22bombadil=2Einfradead=2Eorg=22=2C?= =?utf-8?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_original?= =?utf-8?q?_message_has_been_attached_to_this_so_you_can_view_it_or_label?= =?utf-8?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?utf-8?q?_the_administrator_of_that_system_for_details=2E?= =?utf-8?q?_?= =?utf-8?q?_Content_preview=3A__From=3A_Rafa=C3=85=C2=82_Mi=C3=85=C2=82ecki_1?= =?utf-8?q?=2E_Don=27t_hardcode_=22partition-=22_string?= =?utf-8?q?_twice_2=2E_Use_simpler_logic_=26_use_-=3Ename_to_avoid_of=5Fprope?= =?utf-8?q?rty=5Fread=5Fstring=28=29?= =?utf-8?q?_3=2E_Use_mtd=5Fget=5Fof=5Fnode=28=29_helper_Cc=3A_Christian_Maran?= =?utf-8?q?gi_Signed-off-by=3A_Rafa=C3=85=C2=82?= =?utf-8?q?_Mi=C3=85=C2=82ecki_---_drivers/mtd/mtdcore=2Ec_=7C_16_+++++++----?= =?utf-8?q?-----_1_file_changed=2C?= =?utf-8?q?_7_insertions=28+=29=2C_9_deletions=28-=29_?= =?utf-8?q?_?= =?utf-8?q?_Content_analysis_details=3A___=280=2E1_points=2C_5=2E0_required?= =?utf-8?q?=29?= =?utf-8?q?_?= =?utf-8?q?_pts_rule_name______________description?= =?utf-8?q?_----_----------------------_-------------------------------------?= =?utf-8?q?-------------?= =?utf-8?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_at_https?= =?utf-8?q?=3A//www=2Ednswl=2Eorg/=2C?= =?utf-8?q?_no_trust?= =?utf-8?b?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDo1MjkgbGlzdGVkIGluXQ==?= =?utf-8?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?utf-8?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_record?= =?utf-8?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publish_an_?= =?utf-8?q?SPF_Record?= =?utf-8?q?_0=2E0_FREEMAIL=5FFROM__________Sender_email_is_commonly_abused_en?= =?utf-8?q?duser_mail?= =?utf-8?q?_provider?= =?utf-8?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?utf-8?q?_0=2E2_FREEMAIL=5FENVFROM=5FEND=5FDIGIT_Envelope-from_freemail_use?= =?utf-8?q?rname_ends?= =?utf-8?q?_in_digit?= =?utf-8?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?utf-8?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM_or_DK_?= =?utf-8?q?signature_from?= =?utf-8?q?_author=27s_domain?= =?utf-8?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_valid_DK?= =?utf-8?q?IM_or_DK_signature?= =?utf-8?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_signature?= =?utf-8?q?=2C_not_necessarily?= =?utf-8?q?_valid?= =?utf-8?q?_-0=2E1_DKIM=5FVALID=5FEF__________Message_has_a_valid_DKIM_or_DK_?= =?utf-8?q?signature_from?= =?utf-8?q?_envelope-from_domain?= X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org From: Rafał Miłecki 1. Don't hardcode "partition-" string twice 2. Use simpler logic & use ->name to avoid of_property_read_string() 3. Use mtd_get_of_node() helper Cc: Christian Marangi Signed-off-by: Rafał Miłecki --- drivers/mtd/mtdcore.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 18aa54460d36..2211e0ed6cc9 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -551,18 +551,16 @@ static void mtd_check_of_node(struct mtd_info *mtd) struct device_node *partitions, *parent_dn, *mtd_dn = NULL; const char *pname, *prefix = "partition-"; int plen, mtd_name_len, offset, prefix_len; - struct mtd_info *parent; bool found = false; /* Check if MTD already has a device node */ - if (dev_of_node(&mtd->dev)) + if (mtd_get_of_node(mtd)) return; /* Check if a partitions node exist */ if (!mtd_is_partition(mtd)) return; - parent = mtd->parent; - parent_dn = dev_of_node(&parent->dev); + parent_dn = mtd_get_of_node(mtd->parent); if (!parent_dn) return; @@ -575,15 +573,15 @@ static void mtd_check_of_node(struct mtd_info *mtd) /* Search if a partition is defined with the same name */ for_each_child_of_node(partitions, mtd_dn) { - offset = 0; - /* Skip partition with no/wrong prefix */ - if (!of_node_name_prefix(mtd_dn, "partition-")) + if (!of_node_name_prefix(mtd_dn, prefix)) continue; /* Label have priority. Check that first */ - if (of_property_read_string(mtd_dn, "label", &pname)) { - of_property_read_string(mtd_dn, "name", &pname); + if (!of_property_read_string(mtd_dn, "label", &pname)) { + offset = 0; + } else { + pname = mtd_dn->name; offset = prefix_len; }