Skip to content

Commit 1b760fd

Browse files
hkallweitgregkh
authored andcommitted
mmc: sdio: fix alignment issue in struct sdio_func
[ Upstream commit 5ef1ecf060f28ecef313b5723f1fd39bf5a35f56 ] Certain 64-bit systems (e.g. Amlogic Meson GX) require buffers to be used for DMA to be 8-byte-aligned. struct sdio_func has an embedded small DMA buffer not meeting this requirement. When testing switching to descriptor chain mode in meson-gx driver SDIO is broken therefore. Fix this by allocating the small DMA buffer separately as kmalloc ensures that the returned memory area is properly aligned for every basic data type. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Tested-by: Helmut Klein <hgkr.klein@gmail.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e1e99dc commit 1b760fd

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

drivers/mmc/core/sdio_bus.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static void sdio_release_func(struct device *dev)
266266
sdio_free_func_cis(func);
267267

268268
kfree(func->info);
269-
269+
kfree(func->tmpbuf);
270270
kfree(func);
271271
}
272272

@@ -281,6 +281,16 @@ struct sdio_func *sdio_alloc_func(struct mmc_card *card)
281281
if (!func)
282282
return ERR_PTR(-ENOMEM);
283283

284+
/*
285+
* allocate buffer separately to make sure it's properly aligned for
286+
* DMA usage (incl. 64 bit DMA)
287+
*/
288+
func->tmpbuf = kmalloc(4, GFP_KERNEL);
289+
if (!func->tmpbuf) {
290+
kfree(func);
291+
return ERR_PTR(-ENOMEM);
292+
}
293+
284294
func->card = card;
285295

286296
device_initialize(&func->dev);

include/linux/mmc/sdio_func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct sdio_func {
5353
unsigned int state; /* function state */
5454
#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
5555

56-
u8 tmpbuf[4]; /* DMA:able scratch buffer */
56+
u8 *tmpbuf; /* DMA:able scratch buffer */
5757

5858
unsigned num_info; /* number of info strings */
5959
const char **info; /* info strings */

0 commit comments

Comments
 (0)