Skip to contentSkip to conversation

Raspberry Pi sdhost cleanups

PATCH In review Lukas Wunner 3 participants 7 messages Feb 3, 2019 – Feb 5, 2019 4 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover Raspberry Pi sdhost cleanups

Three mostly trivial cleanups for the Raspberry Pi sdhost driver, v2.

Only change since v1: Use container_of() in patch [2/3] instead of open-coding the same (Alexander Graf).

The issue addressed by patch [2/3] appears to be present in 32 other drivers as can be seen with "git grep -e '->mmc = ' -- drivers/mmc/host". Perhaps cleaning them up would be suitable for Outreachy applicants to get their feet wet? Adding Shraddha Barke and Vaishali Thakkar to cc.

Thanks,

Lukas

Lukas Wunner (3):
mmc: bcm2835: Drop DMA channel error pointer check
mmc: bcm2835: Drop pointer to mmc_host from bcm2835_host
mmc: bcm2835: Deduplicate reset of driver data on remove

 drivers/mmc/host/bcm2835.c | 23 +++++++++++------------
 include/linux/mmc/host.h   |  5 +++++
 2 files changed, 16 insertions(+), 12 deletions(-)
Signature · 1 line
2.20.1

A message that is not in the archive (sent off-list or not yet received): cover.1549181242.git.lukas-JFq808J9C/[email protected]

#2 lore raw

PATCH v2 1/3 mmc: bcm2835: Drop DMA channel error pointer check

bcm2835_add_host() invokes IS_ERR_OR_NULL() on a DMA channel pointer, however dma_request_slave_channel() (which was used to populate the pointer) never returns an error pointer. So a NULL pointer check is sufficient.

---
 drivers/mmc/host/bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/bcm2835.c +1 -1
index c9e7aa50bb0a..ab8d58a60352 100644
@@ -1286,7 +1286,7 @@ static int bcm2835_add_host(struct bcm2835_host *host)
 	spin_lock_init(&host->lock);
 	mutex_init(&host->mutex);
 
-	if (IS_ERR_OR_NULL(host->dma_chan_rxtx)) {
+	if (!host->dma_chan_rxtx) {
 		dev_warn(dev, "unable to initialise DMA channel. Falling back to PIO\n");
 		host->use_dma = false;
 	} else {
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 2/3 mmc: bcm2835: Drop pointer to mmc_host from bcm2835_host

In reply to a message not in the archive

The BCM2835 MMC host driver uses a pointer to get from the private bcm2835_host structure to the generic mmc_host structure. However the latter is always immediately preceding the former in memory, so compute its address with a subtraction (which is cheaper than a dereference) and drop the superfluous pointer.

No functional change intended.

Cc Frank Pavlic <f.pavlic-XB/[email protected]>
Cc Alexander Graf <[email protected]>
---
 drivers/mmc/host/bcm2835.c | 20 ++++++++++----------
 include/linux/mmc/host.h   |  5 +++++
 2 files changed, 15 insertions(+), 10 deletions(-)
drivers/mmc/host/bcm2835.c +10 -10
index ab8d58a60352..246c8ec24148 100644
@@ -148,7 +148,6 @@ struct bcm2835_host {
 	void __iomem		*ioaddr;
 	u32			phys_addr;
 
-	struct mmc_host		*mmc;
 	struct platform_device	*pdev;
 
 	int			clock;		/* Current clock speed */
@@ -618,7 +617,7 @@ static void bcm2835_finish_request(struct bcm2835_host *host)
 				"failed to terminate DMA (%d)\n", err);
 	}
 
-	mmc_request_done(host->mmc, mrq);
+	mmc_request_done(mmc_from_priv(host), mrq);
 }
 
 static
@@ -837,7 +836,7 @@ static void bcm2835_timeout(struct work_struct *work)
 		dev_err(dev, "timeout waiting for hardware interrupt.\n");
 		bcm2835_dumpregs(host);
 
-		bcm2835_reset(host->mmc);
+		bcm2835_reset(mmc_from_priv(host));
 
 		if (host->data) {
 			host->data->error = -ETIMEDOUT;
@@ -1100,6 +1099,7 @@ static void bcm2835_dma_complete_work(struct work_struct *work)
 
 static void bcm2835_set_clock(struct bcm2835_host *host, unsigned int clock)
 {
+	struct mmc_host *mmc = mmc_from_priv(host);
 	int div;
 
 	/* The SDCDIV register has 11 bits, and holds (div - 2).  But
@@ -1143,18 +1143,18 @@ static void bcm2835_set_clock(struct bcm2835_host *host, unsigned int clock)
 		div = SDCDIV_MAX_CDIV;
 
 	clock = host->max_clk / (div + 2);
-	host->mmc->actual_clock = clock;
+	mmc->actual_clock = clock;
 
 	/* Calibrate some delays */
 
 	host->ns_per_fifo_word = (1000000000 / clock) *
-		((host->mmc->caps & MMC_CAP_4_BIT_DATA) ? 8 : 32);
+		((mmc->caps & MMC_CAP_4_BIT_DATA) ? 8 : 32);
 
 	host->cdiv = div;
 	writel(host->cdiv, host->ioaddr + SDCDIV);
 
 	/* Set the timeout to 500ms */
-	writel(host->mmc->actual_clock / 2, host->ioaddr + SDTOUT);
+	writel(mmc->actual_clock / 2, host->ioaddr + SDTOUT);
 }
 
 static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
@@ -1264,7 +1264,7 @@ static const struct mmc_host_ops bcm2835_ops = {
 
 static int bcm2835_add_host(struct bcm2835_host *host)
 {
-	struct mmc_host *mmc = host->mmc;
+	struct mmc_host *mmc = mmc_from_priv(host);
 	struct device *dev = &host->pdev->dev;
 	char pio_limit_string[20];
 	int ret;
@@ -1370,7 +1370,6 @@ static int bcm2835_probe(struct platform_device *pdev)
 
 	mmc->ops = &bcm2835_ops;
 	host = mmc_priv(mmc);
-	host->mmc = mmc;
 	host->pdev = pdev;
 	spin_lock_init(&host->lock);
 
@@ -1441,8 +1440,9 @@ static int bcm2835_probe(struct platform_device *pdev)
 static int bcm2835_remove(struct platform_device *pdev)
 {
 	struct bcm2835_host *host = platform_get_drvdata(pdev);
+	struct mmc_host *mmc = mmc_from_priv(host);
 
-	mmc_remove_host(host->mmc);
+	mmc_remove_host(mmc);
 
 	writel(SDVDD_POWER_OFF, host->ioaddr + SDVDD);
 
@@ -1454,7 +1454,7 @@ static int bcm2835_remove(struct platform_device *pdev)
 	if (host->dma_chan_rxtx)
 		dma_release_channel(host->dma_chan_rxtx);
 
-	mmc_free_host(host->mmc);
+	mmc_free_host(mmc);
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
include/linux/mmc/host.h +5 -0
index 4d35ff36ceff..d893902b2f1c 100644
@@ -478,6 +478,11 @@ static inline void *mmc_priv(struct mmc_host *host)
 	return (void *)host->private;
 }
 
+static inline struct mmc_host *mmc_from_priv(void *priv)
+{
+	return container_of(priv, struct mmc_host, private);
+}
+
 #define mmc_host_is_spi(host)	((host)->caps & MMC_CAP_SPI)
 
 #define mmc_dev(x)	((x)->parent)
Signature · 1 line
2.20.1

A message that is not in the archive (sent off-list or not yet received): ffa656c9f2c0e397a38e5827ba586f13e723f81b.1549181242.git.lukas-JFq808J9C/[email protected]

Reviewed-by
#5 lore raw

Re: [PATCH v2 2/3] mmc: bcm2835: Drop pointer to mmc_host from bcm2835_host

Quoted 10 lines

Am 03.02.2019 um 09:27 schrieb Lukas Wunner <lukas-JFq808J9C/[email protected]>:

The BCM2835 MMC host driver uses a pointer to get from the private bcm2835_host structure to the generic mmc_host structure. However the latter is always immediately preceding the former in memory, so compute its address with a subtraction (which is cheaper than a dereference) and drop the superfluous pointer.

Quoted 5 lines

No functional change intended.

Cc Frank Pavlic <f.pavlic-XB/[email protected]>
Cc Alexander Graf <[email protected]>

Alex

#6 lore raw

PATCH v2 3/3 mmc: bcm2835: Deduplicate reset of driver data on remove

In reply to a message not in the archive

The BCM2835 MMC host driver sets the device's driver data pointer to NULL on ->remove() even though the driver core subsequently does the same in __device_release_driver(). Drop the duplicate assignment.

---
 drivers/mmc/host/bcm2835.c | 1 -
 1 file changed, 1 deletion(-)
drivers/mmc/host/bcm2835.c +0 -1
index 246c8ec24148..7e0d3a49c06d 100644
@@ -1455,7 +1455,6 @@ static int bcm2835_remove(struct platform_device *pdev)
 		dma_release_channel(host->dma_chan_rxtx);
 
 	mmc_free_host(mmc);
-	platform_set_drvdata(pdev, NULL);
 
 	return 0;
 }
Signature · 1 line
2.20.1
#7 lore raw
In reply to a message not in the archive
Quoted 21 lines · Lukas Wunner

Three mostly trivial cleanups for the Raspberry Pi sdhost driver, v2.

Only change since v1: Use container_of() in patch [2/3] instead of open-coding the same (Alexander Graf).

The issue addressed by patch [2/3] appears to be present in 32 other drivers as can be seen with "git grep -e '->mmc = ' -- drivers/mmc/host". Perhaps cleaning them up would be suitable for Outreachy applicants to get their feet wet? Adding Shraddha Barke and Vaishali Thakkar to cc.

Thanks,

Lukas

Lukas Wunner (3):
mmc: bcm2835: Drop DMA channel error pointer check
mmc: bcm2835: Drop pointer to mmc_host from bcm2835_host
mmc: bcm2835: Deduplicate reset of driver data on remove

Quoted 7 lines
 drivers/mmc/host/bcm2835.c | 23 +++++++++++------------
 include/linux/mmc/host.h   |  5 +++++
 2 files changed, 16 insertions(+), 12 deletions(-)

--
2.20.1

Applied for next, thanks!

Kind regards
Uffe

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): 20190205132652.xpy2aygu33lm43sz-JFq808J9C/[email protected]

#10 lore raw
Quoted 13 lines · Lukas Wunner
Quoted 10 lines · Ulf Hansson
Quoted 9 lines · Lukas Wunner

Three mostly trivial cleanups for the Raspberry Pi sdhost driver, v2.

Only change since v1: Use container_of() in patch [2/3] instead of open-coding the same (Alexander Graf).

The issue addressed by patch [2/3] appears to be present in 32 other drivers as can be seen with "git grep -e '->mmc = ' -- drivers/mmc/host". Perhaps cleaning them up would be suitable for Outreachy applicants to get their feet wet? Adding Shraddha Barke and Vaishali Thakkar to cc.

Quoted 4 lines

FWIW this is now documented as something for Outreachy applicants to look into, I hope that's okay:

https://github.com/nerdyvaishali/kernelbridge/commit/6f8cbf7f8e36

Great, cool, thanks! :-)

Kind regards
Uffe