From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Christian Marangi <ansuelsmth@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>, Jonathan Corbet <corbet@lwn.net>,
Ulf Hansson <ulf.hansson@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
INAGAKI Hiroshi <musashino.open@gmail.com>,
Daniel Golle <daniel@makrotopia.org>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Li Lingfeng <lilingfeng3@huawei.com>,
Christian Heusel <christian@heusel.eu>,
linux-block@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org,
devicetree@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>,
Lorenzo Bianconi <lorenzo@kernel.org>,
upstream@airoha.com
Subject: Re: [PATCH v3 3/4] block: add support for partition table defined in OF
Date: Mon, 30 Sep 2024 11:21:53 +0200 [thread overview]
Message-ID: <877catlcni.fsf@prevas.dk> (raw)
In-Reply-To: <20240929140713.6883-4-ansuelsmth@gmail.com> (Christian Marangi's message of "Sun, 29 Sep 2024 16:06:19 +0200")
Christian Marangi <ansuelsmth@gmail.com> writes:
> diff --git a/block/partitions/of.c b/block/partitions/of.c
> new file mode 100644
> index 000000000000..bc6200eb86b3
> --- /dev/null
> +++ b/block/partitions/of.c
> @@ -0,0 +1,151 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/blkdev.h>
> +#include <linux/major.h>
> +#include <linux/of.h>
> +#include "check.h"
> +
> +#define BOOT0_STR "boot0"
> +#define BOOT1_STR "boot1"
> +
> +static struct device_node *get_partitions_node(struct device_node *disk_np,
> + struct gendisk *disk)
> +{
> + const char *node_name = "partitions";
> +
> + /*
> + * JEDEC specification 4.4 for eMMC introduced 3 additional partition
> + * present on every eMMC. These additional partition are always hardcoded
> + * from the eMMC driver as boot0, boot1 and rpmb. While rpmb is used to
> + * store keys and exposed as a char device, the other 2 are exposed as
> + * real separate disk with the boot0/1 appended to the disk name.
> + *
> + * Here we parse the disk_name in search for such suffix and select
> + * the correct partition node.
> + */
> + if (disk->major == MMC_BLOCK_MAJOR) {
> + const char *disk_name = disk->disk_name;
> +
> + if (!memcmp(disk_name + strlen(disk_name) - strlen(BOOT0_STR),
> + BOOT0_STR, sizeof(BOOT0_STR)))
> + node_name = "partitions-boot0";
If strlen(disk_name) is less than 5 (and I don't know if that's actually
possible), this well end up doing out-of-bounds access.
We have a strstarts() helper, could you also add a strends() helper that
handles this correctly? Something like
/**
* strends - does @str end with @suffix?
* @str: string to examine
* @suffix: suffix to look for.
*/
static inline bool strends(const char *str, const char *suffix)
{
size_t n = strlen(str);
size_t m = strlen(suffix);
return n >= m && !memcmp(str + n - m, suffix, m);
}
[or name it str_has_suffix() or str_ends_with(), "strends" is not
particularly readable, it's unfortunate that the existing strstarts is
spelled like that].
Rasmus
next prev parent reply other threads:[~2024-09-30 9:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-29 14:06 [PATCH v3 0/4] block: partition table OF support Christian Marangi
2024-09-29 14:06 ` [PATCH v3 1/4] block: add support for defining read-only partitions Christian Marangi
2024-09-29 14:06 ` [PATCH v3 2/4] docs: block: Document support for read-only partition in cmdline part Christian Marangi
2024-09-29 14:06 ` [PATCH v3 3/4] block: add support for partition table defined in OF Christian Marangi
2024-09-30 8:14 ` Sascha Hauer
2024-09-30 10:21 ` Christian Marangi
2024-09-30 9:21 ` Rasmus Villemoes [this message]
2024-09-30 10:48 ` Christian Marangi
2024-09-29 14:06 ` [PATCH v3 4/4] dt-bindings: mmc: Document support for partition table in mmc-card Christian Marangi
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=877catlcni.fsf@prevas.dk \
--to=linux@rasmusvillemoes.dk \
--cc=ansuelsmth@gmail.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=christian@heusel.eu \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@makrotopia.org \
--cc=devicetree@vger.kernel.org \
--cc=jack@suse.cz \
--cc=krzk+dt@kernel.org \
--cc=lilingfeng3@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=lorenzo@kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=musashino.open@gmail.com \
--cc=robh@kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=upstream@airoha.com \
--cc=viro@zeniv.linux.org.uk \
/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