From: Torstein Eide <torsteine+linux@gmail.com>
To: linux-mmc@vger.kernel.org
Cc: Torstein Eide <torsteine+linux@gmail.com>
Subject: [PATCH v5 2/3] mmc-utils: lsmmc: Factor out CID month/year helpers
Date: Sun, 9 Aug 2026 10:21:52 +0200 [thread overview]
Message-ID: <20260809082153.104311-3-torsteine+linux@gmail.com> (raw)
In-Reply-To: <20260809082153.104311-1-torsteine+linux@gmail.com>
print_sd_cid() and print_mmc_cid() each keep their own copy of the
month-name table, and print_mmc_cid() open-codes the ext_csd_rev
based base-year adjustment inline. Extract both into shared helpers,
month_name(), sd_cid_year() and mmc_cid_year(), so there is a single
place to fix or extend the manufacturing-date decoding.
No functional change.
Signed-off-by: Torstein Eide <torsteine+linux@gmail.com>
---
lsmmc.c | 66 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 25 deletions(-)
diff --git a/lsmmc.c b/lsmmc.c
index d5a26b6..3139a7d 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -490,13 +490,45 @@ static void parse_mmc_cid(char *raw, struct mmc_cid *c)
}
/* MMC/SD information parsing functions */
-static void print_sd_cid(struct config *config, char *cid)
+static const char *month_name(unsigned int month)
{
static const char *months[] = { "invalid0",
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec",
"invalid1", "invalid2", "invalid3",
};
+
+ if (month >= ARRAY_SIZE(months))
+ return "invalid";
+
+ return months[month];
+}
+
+static unsigned int sd_cid_year(const struct sd_cid *c)
+{
+ return 2000 + c->mdt_year;
+}
+
+static unsigned int mmc_cid_year(const struct mmc_cid *c, unsigned int ext_csd_rev)
+{
+ unsigned int base_year = 1997;
+
+ if (ext_csd_rev) {
+ /* Adjust base year according to ext_csd_rev */
+ if (ext_csd_rev > 8) {
+ base_year = 2029;
+ if (c->mdt_year >= 13)
+ base_year = 2013;
+ } else if (ext_csd_rev > 4) {
+ base_year = 2013;
+ }
+ }
+
+ return base_year + c->mdt_year;
+}
+
+static void print_sd_cid(struct config *config, char *cid)
+{
struct sd_cid c;
char *manufacturer;
@@ -514,15 +546,15 @@ static void print_sd_cid(struct config *config, char *cid)
printf("(%u.%u)\n", c.prv_major, c.prv_minor);
printf("\tPSN: 0x%08x\n", c.psn);
printf("\tMDT: 0x%02x%01x %u %s\n", c.mdt_year, c.mdt_month,
- 2000 + c.mdt_year, months[c.mdt_month]);
+ sd_cid_year(&c), month_name(c.mdt_month));
printf("\tCRC: 0x%02x\n", c.crc);
} else {
printf("manufacturer: '%s' '%s'\n", manufacturer, c.oid);
printf("product: '%s' %u.%u\n", c.pnm, c.prv_major, c.prv_minor);
printf("serial: 0x%08x\n", c.psn);
- printf("manufacturing date: %u %s\n", 2000 + c.mdt_year,
- months[c.mdt_month]);
+ printf("manufacturing date: %u %s\n", sd_cid_year(&c),
+ month_name(c.mdt_month));
}
free(manufacturer);
@@ -530,29 +562,13 @@ static void print_sd_cid(struct config *config, char *cid)
static void print_mmc_cid(struct config *config, char *cid)
{
- static const char *months[] = { "invalid0",
- "jan", "feb", "mar", "apr", "may", "jun",
- "jul", "aug", "sep", "oct", "nov", "dec",
- "invalid1", "invalid2", "invalid3",
- };
struct mmc_cid c;
char *manufacturer;
- int base_year = 1997;
+ unsigned int year;
parse_mmc_cid(cid, &c);
manufacturer = get_manufacturer(config, c.mid);
-
- if (config->ext_csd_rev) {
- /* Adjust base year according to ext_csd_rev */
- if (config->ext_csd_rev > 8) {
- base_year = 2029;
- if (c.mdt_year >= 13)
- base_year = 2013;
- } else if (config->ext_csd_rev > 4) {
- base_year = 2013;
- }
- }
-
+ year = mmc_cid_year(&c, config->ext_csd_rev);
if (config->verbose) {
printf("======MMC/CID======\n");
@@ -581,7 +597,7 @@ static void print_mmc_cid(struct config *config, char *cid)
printf("(%u.%u)\n", c.prv_major, c.prv_minor);
printf("\tPSN: 0x%08x\n", c.psn);
printf("\tMDT: 0x%01x%01x %u %s\n", c.mdt_month, c.mdt_year,
- base_year + c.mdt_year, months[c.mdt_month]);
+ year, month_name(c.mdt_month));
if (!config->ext_csd_rev)
printf("\tWarn: ext_csd_rev not provided, "
"manufacturing date year may be wrong.\n");
@@ -592,8 +608,8 @@ static void print_mmc_cid(struct config *config, char *cid)
printf("product: '%s' %u.%u\n", c.pnm, c.prv_major, c.prv_minor);
printf("serial: 0x%08x\n", c.psn);
- printf("manufacturing date: %u %s\n", base_year + c.mdt_year,
- months[c.mdt_month]);
+ printf("manufacturing date: %u %s\n", year,
+ month_name(c.mdt_month));
if (!config->ext_csd_rev)
printf("Warn: ext_csd_rev not provided, "
"manufacturing date year may be wrong.\n");
--
2.53.0
next prev parent reply other threads:[~2026-08-09 8:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-09 8:21 [PATCH v5 0/3] mmc-utils: lsmmc: add 'mmc list' command Torstein Eide
2026-08-09 8:21 ` [PATCH v5 1/3] mmc-utils: lsmmc: Use external .ids files and accept /dev, /sys/block paths Torstein Eide
2026-08-09 8:21 ` Torstein Eide [this message]
2026-08-09 8:21 ` [PATCH v5 3/3] mmc-utils: lsmmc: Add mmc list command Torstein Eide
2026-08-10 5:46 ` [PATCH v5 0/3] mmc-utils: lsmmc: add 'mmc list' command Avri Altman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260809082153.104311-3-torsteine+linux@gmail.com \
--to=torsteine+linux@gmail.com \
--cc=linux-mmc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox