linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] mtd: ftl: use container_of() rather than cast
@ 2022-08-16 13:59 Gaosheng Cui
  2022-09-19 16:15 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Gaosheng Cui @ 2022-08-16 13:59 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, cuigaosheng1
  Cc: linux-mtd, linux-kernel, wangweiyang2

The container_of() is much more readable and also safer.

Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
---
 drivers/mtd/ftl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index bec56070039d..7e56c77535e8 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -941,7 +941,7 @@ static int ftl_write(partition_t *part, caddr_t buffer,
 
 static int ftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo)
 {
-	partition_t *part = (void *)dev;
+	partition_t *part = container_of(dev, struct partition_t, mbd);
 	u_long sect;
 
 	/* Sort of arbitrary: round size down to 4KiB boundary */
@@ -969,7 +969,7 @@ static int ftl_writesect(struct mtd_blktrans_dev *dev,
 static int ftl_discardsect(struct mtd_blktrans_dev *dev,
 			   unsigned long sector, unsigned nr_sects)
 {
-	partition_t *part = (void *)dev;
+	partition_t *part = container_of(dev, struct partition_t, mbd);
 	uint32_t bsize = 1 << part->header.EraseUnitSize;
 
 	pr_debug("FTL erase sector %ld for %d sectors\n",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] mtd: ftl: use container_of() rather than cast
  2022-08-16 13:59 [PATCH -next] mtd: ftl: use container_of() rather than cast Gaosheng Cui
@ 2022-09-19 16:15 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2022-09-19 16:15 UTC (permalink / raw)
  To: Gaosheng Cui, miquel.raynal, richard, vigneshr
  Cc: linux-mtd, linux-kernel, wangweiyang2

On Tue, 2022-08-16 at 13:59:10 UTC, Gaosheng Cui wrote:
> The container_of() is much more readable and also safer.
> 
> Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-19 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 13:59 [PATCH -next] mtd: ftl: use container_of() rather than cast Gaosheng Cui
2022-09-19 16:15 ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).