* [PATCH 1/2] block: allow setting partition of_node
@ 2025-03-04 17:06 Daniel Golle
2025-03-04 17:06 ` [PATCH 2/2] block: partitions: of: assign Device Tree node to partition Daniel Golle
2025-04-01 1:39 ` [PATCH 1/2] block: allow setting partition of_node Christian Marangi
0 siblings, 2 replies; 4+ messages in thread
From: Daniel Golle @ 2025-03-04 17:06 UTC (permalink / raw)
To: Jens Axboe, Daniel Golle, Christian Marangi, Al Viro,
Douglas Anderson, Christian Brauner, Riyan Dhiman,
Konstantin Khlebnikov, Li Lingfeng, linux-block, linux-kernel
Allow partition parsers to set the Device Tree node for a partition by
introducing of_put_partition() and extending struct parsed_partitions
accordingly.
As the partition information is preallocated independently of the actual
number of partitions the additional pointer takes about 2 kiB of allocated
memory which is worth avoiding in case CONFIG_OF is not set. This is
achieved by only adding the corresponding field to the struct in case
CONFIG_OF is set using #ifdef'ery.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
block/partitions/check.h | 16 +++++++++++++++-
block/partitions/core.c | 14 +++++++++++---
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/block/partitions/check.h b/block/partitions/check.h
index e5c1c61eb3532..0b326086b1b61 100644
--- a/block/partitions/check.h
+++ b/block/partitions/check.h
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include <linux/pagemap.h>
#include <linux/blkdev.h>
+#include <linux/of.h>
#include "../blk.h"
/*
@@ -16,6 +17,9 @@ struct parsed_partitions {
int flags;
bool has_info;
struct partition_meta_info info;
+#ifdef CONFIG_OF
+ struct device_node *np;
+#endif
} *parts;
int next;
int limit;
@@ -34,18 +38,28 @@ static inline void put_dev_sector(Sector p)
}
static inline void
-put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
+of_put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size,
+ struct device_node *np)
{
if (n < p->limit) {
char tmp[1 + BDEVNAME_SIZE + 10 + 1];
p->parts[n].from = from;
p->parts[n].size = size;
+#ifdef CONFIG_OF
+ p->parts[n].np = np;
+#endif
snprintf(tmp, sizeof(tmp), " %s%d", p->name, n);
strlcat(p->pp_buf, tmp, PAGE_SIZE);
}
}
+static inline void
+put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
+{
+ of_put_partition(p, n, from, size, NULL);
+}
+
/* detection routines go here in alphabetical order: */
int adfspart_check_ADFS(struct parsed_partitions *state);
int adfspart_check_CUMANA(struct parsed_partitions *state);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 815ed33caa1b8..70d1ad8e37b93 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -9,6 +9,7 @@
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/vmalloc.h>
+#include <linux/device.h>
#include <linux/raid/detect.h>
#include "check.h"
@@ -292,7 +293,8 @@ static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
*/
static struct block_device *add_partition(struct gendisk *disk, int partno,
sector_t start, sector_t len, int flags,
- struct partition_meta_info *info)
+ struct partition_meta_info *info,
+ struct device_node *np)
{
dev_t devt = MKDEV(0, 0);
struct device *ddev = disk_to_dev(disk);
@@ -341,6 +343,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
pdev->class = &block_class;
pdev->type = &part_type;
pdev->parent = ddev;
+ device_set_node(pdev, of_fwnode_handle(np));
/* in consecutive minor range? */
if (bdev_partno(bdev) < disk->minors) {
@@ -447,7 +450,7 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
}
part = add_partition(disk, partno, start, length,
- ADDPART_FLAG_NONE, NULL);
+ ADDPART_FLAG_NONE, NULL, NULL);
ret = PTR_ERR_OR_ZERO(part);
out:
mutex_unlock(&disk->open_mutex);
@@ -561,8 +564,13 @@ static bool blk_add_partition(struct gendisk *disk,
size = get_capacity(disk) - from;
}
+#ifdef CONFIG_OF
part = add_partition(disk, p, from, size, state->parts[p].flags,
- &state->parts[p].info);
+ &state->parts[p].info, state->parts[p].np);
+#else
+ part = add_partition(disk, p, from, size, state->parts[p].flags,
+ &state->parts[p].info, NULL);
+#endif
if (IS_ERR(part)) {
if (PTR_ERR(part) != -ENXIO) {
printk(KERN_ERR " %s: p%d could not be added: %pe\n",
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] block: partitions: of: assign Device Tree node to partition
2025-03-04 17:06 [PATCH 1/2] block: allow setting partition of_node Daniel Golle
@ 2025-03-04 17:06 ` Daniel Golle
2025-04-01 1:40 ` Christian Marangi
2025-04-01 1:39 ` [PATCH 1/2] block: allow setting partition of_node Christian Marangi
1 sibling, 1 reply; 4+ messages in thread
From: Daniel Golle @ 2025-03-04 17:06 UTC (permalink / raw)
To: Jens Axboe, Daniel Golle, Christian Marangi, Al Viro,
Douglas Anderson, Christian Brauner, Riyan Dhiman,
Konstantin Khlebnikov, Li Lingfeng, linux-block, linux-kernel
Assign partition of_node so other drivers are able to identify a
partition by its Device Tree node.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
block/partitions/of.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/partitions/of.c b/block/partitions/of.c
index 4e760fdffb3fe..8b82f9f396866 100644
--- a/block/partitions/of.c
+++ b/block/partitions/of.c
@@ -48,7 +48,7 @@ static void add_of_partition(struct parsed_partitions *state, int slot,
u64 offset = of_read_number(reg, a_cells) / SECTOR_SIZE;
u64 size = of_read_number(reg + a_cells, s_cells) / SECTOR_SIZE;
- put_partition(state, slot, offset, size);
+ of_put_partition(state, slot, offset, size, np);
if (of_property_read_bool(np, "read-only"))
state->parts[slot].flags |= ADDPART_FLAG_READONLY;
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] block: partitions: of: assign Device Tree node to partition
2025-03-04 17:06 ` [PATCH 2/2] block: partitions: of: assign Device Tree node to partition Daniel Golle
@ 2025-04-01 1:40 ` Christian Marangi
0 siblings, 0 replies; 4+ messages in thread
From: Christian Marangi @ 2025-04-01 1:40 UTC (permalink / raw)
To: Daniel Golle
Cc: Jens Axboe, Al Viro, Douglas Anderson, Christian Brauner,
Riyan Dhiman, Konstantin Khlebnikov, Li Lingfeng, linux-block,
linux-kernel
On Tue, Mar 04, 2025 at 05:06:17PM +0000, Daniel Golle wrote:
> Assign partition of_node so other drivers are able to identify a
> partition by its Device Tree node.
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Christian Marangi <ansuelsmth@gmail.com>
--
Ansuel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] block: allow setting partition of_node
2025-03-04 17:06 [PATCH 1/2] block: allow setting partition of_node Daniel Golle
2025-03-04 17:06 ` [PATCH 2/2] block: partitions: of: assign Device Tree node to partition Daniel Golle
@ 2025-04-01 1:39 ` Christian Marangi
1 sibling, 0 replies; 4+ messages in thread
From: Christian Marangi @ 2025-04-01 1:39 UTC (permalink / raw)
To: Daniel Golle
Cc: Jens Axboe, Al Viro, Douglas Anderson, Christian Brauner,
Riyan Dhiman, Konstantin Khlebnikov, Li Lingfeng, linux-block,
linux-kernel
On Tue, Mar 04, 2025 at 05:06:01PM +0000, Daniel Golle wrote:
> Allow partition parsers to set the Device Tree node for a partition by
> introducing of_put_partition() and extending struct parsed_partitions
> accordingly.
>
> As the partition information is preallocated independently of the actual
> number of partitions the additional pointer takes about 2 kiB of allocated
> memory which is worth avoiding in case CONFIG_OF is not set. This is
> achieved by only adding the corresponding field to the struct in case
> CONFIG_OF is set using #ifdef'ery.
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
I also think ifdef for OF is a necessity in this case to prevent the struct
size to explode.
Reviewed-by: Christian Marangi <ansuelsmth@gmail.com>
--
Ansuel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-01 1:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-04 17:06 [PATCH 1/2] block: allow setting partition of_node Daniel Golle
2025-03-04 17:06 ` [PATCH 2/2] block: partitions: of: assign Device Tree node to partition Daniel Golle
2025-04-01 1:40 ` Christian Marangi
2025-04-01 1:39 ` [PATCH 1/2] block: allow setting partition of_node Christian Marangi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox