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

mmc: Add helper function to check if a card is removable

There are two checks that need to be made when determining whether a
card is removable. A host controller may set MMC_CAP_NONREMOVABLE if the
controller does not support removing cards (e.g. eMMC), in which case
the card is physically non-removable. Also the 'mmc_assume_removable'
module parameter can be configured at module load time, in which case
the card may be logically non-removable.

A helper function keeps the logic in one place so that code always
checks both conditions.

Because this new function is likely to be called from modules we now
need to export the mmc_assume_removable symbol.

Signed-off-by: Matt Fleming <matt@console-pimps.org>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by

Matt Fleming and committed by
Chris Ball
71d7d3d1 d3c502b8

+11 -3
+1
drivers/mmc/core/core.c
··· 58 58 #else 59 59 int mmc_assume_removable = 1; 60 60 #endif 61 + EXPORT_SYMBOL(mmc_assume_removable); 61 62 module_param_named(removable, mmc_assume_removable, bool, 0644); 62 63 MODULE_PARM_DESC( 63 64 removable,
-1
drivers/mmc/core/core.h
··· 58 58 59 59 /* Module parameters */ 60 60 extern int use_spi_crc; 61 - extern int mmc_assume_removable; 62 61 63 62 /* Debugfs information for hosts and cards */ 64 63 void mmc_add_host_debugfs(struct mmc_host *host);
+1 -1
drivers/mmc/core/mmc.c
··· 685 685 { 686 686 const struct mmc_bus_ops *bus_ops; 687 687 688 - if (host->caps & MMC_CAP_NONREMOVABLE || !mmc_assume_removable) 688 + if (!mmc_card_is_removable(host)) 689 689 bus_ops = &mmc_ops_unsafe; 690 690 else 691 691 bus_ops = &mmc_ops;
+1 -1
drivers/mmc/core/sd.c
··· 750 750 { 751 751 const struct mmc_bus_ops *bus_ops; 752 752 753 - if (host->caps & MMC_CAP_NONREMOVABLE || !mmc_assume_removable) 753 + if (!mmc_card_is_removable(host)) 754 754 bus_ops = &mmc_sd_ops_unsafe; 755 755 else 756 756 bus_ops = &mmc_sd_ops;
+8
include/linux/mmc/host.h
··· 267 267 host->disable_delay = disable_delay; 268 268 } 269 269 270 + /* Module parameter */ 271 + extern int mmc_assume_removable; 272 + 273 + static inline int mmc_card_is_removable(struct mmc_host *host) 274 + { 275 + return !(host->caps & MMC_CAP_NONREMOVABLE) && mmc_assume_removable; 276 + } 277 + 270 278 #endif 271 279