Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: ftl: use container_of() rather than cast

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

Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220816135910.268016-1-cuigaosheng1@huawei.com

authored by

Gaosheng Cui and committed by
Miquel Raynal
bf3e6b8f 8d704c4e

+2 -2
+2 -2
drivers/mtd/ftl.c
··· 941 941 942 942 static int ftl_getgeo(struct mtd_blktrans_dev *dev, struct hd_geometry *geo) 943 943 { 944 - partition_t *part = (void *)dev; 944 + partition_t *part = container_of(dev, struct partition_t, mbd); 945 945 u_long sect; 946 946 947 947 /* Sort of arbitrary: round size down to 4KiB boundary */ ··· 969 969 static int ftl_discardsect(struct mtd_blktrans_dev *dev, 970 970 unsigned long sector, unsigned nr_sects) 971 971 { 972 - partition_t *part = (void *)dev; 972 + partition_t *part = container_of(dev, struct partition_t, mbd); 973 973 uint32_t bsize = 1 << part->header.EraseUnitSize; 974 974 975 975 pr_debug("FTL erase sector %ld for %d sectors\n",