Skip to contentSkip to conversation

mmc: slot-gpio: Refactor mmc_gpio_alloc()

PATCH In review Andy Shevchenko 2 participants 4 messages Sep 29, 2021 – Sep 30, 2021 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mmc: slot-gpio: Refactor mmc_gpio_alloc()

Refactor mmc_gpio_alloc() to drop unneeded indentation level and double condition. This increases readability of the code.

---
 drivers/mmc/core/slot-gpio.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/mmc/core/slot-gpio.c +17 -17
index 05e907451df9..e365d328f43c 100644
@@ -39,24 +39,24 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
 
 int mmc_gpio_alloc(struct mmc_host *host)
 {
-	struct mmc_gpio *ctx = devm_kzalloc(host->parent,
-					    sizeof(*ctx), GFP_KERNEL);
-
-	if (ctx) {
-		ctx->cd_debounce_delay_ms = 200;
-		ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL,
-				"%s cd", dev_name(host->parent));
-		if (!ctx->cd_label)
-			return -ENOMEM;
-		ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL,
-				"%s ro", dev_name(host->parent));
-		if (!ctx->ro_label)
-			return -ENOMEM;
-		host->slot.handler_priv = ctx;
-		host->slot.cd_irq = -EINVAL;
-	}
+	const char *devname = dev_name(host->parent);
+	struct mmc_gpio *ctx;
+
+	ctx = devm_kzalloc(host->parent, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		return -ENOMEM;
+
+	ctx->cd_debounce_delay_ms = 200;
+	ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL, "%s cd", devname);
+	if (!ctx->cd_label)
+		return -ENOMEM;
+	ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL, "%s ro", devname);
+	if (!ctx->ro_label)
+		return -ENOMEM;
+	host->slot.handler_priv = ctx;
+	host->slot.cd_irq = -EINVAL;
 
-	return ctx ? 0 : -ENOMEM;
+	return 0;
 }
 
 int mmc_gpio_get_ro(struct mmc_host *host)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 2/2 mmc: slot-gpio: Update default label when no con_id provided

Currently default label of GPIO is assigned to the device name, when no con_id provided. Instead, let's update it to reflect what it's about (use already prepared template).

---
 drivers/mmc/core/slot-gpio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/core/slot-gpio.c +8 -0
index e365d328f43c..dd2a4b6ab6ad 100644
@@ -178,6 +178,10 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id,
 	if (IS_ERR(desc))
 		return PTR_ERR(desc);
 
+	/* Update default label if no con_id provided */
+	if (!con_id)
+		gpiod_set_consumer_name(desc, ctx->cd_label);
+
 	if (debounce) {
 		ret = gpiod_set_debounce(desc, debounce);
 		if (ret < 0)
@@ -226,6 +230,10 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id,
 	if (IS_ERR(desc))
 		return PTR_ERR(desc);
 
+	/* Update default label if no con_id provided */
+	if (!con_id)
+		gpiod_set_consumer_name(desc, ctx->ro_label);
+
 	if (debounce) {
 		ret = gpiod_set_debounce(desc, debounce);
 		if (ret < 0)
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH v1 2/2] mmc: slot-gpio: Update default label when no con_id provided

Quoted 6 lines · Andy Shevchenko

Currently default label of GPIO is assigned to the device name, when no con_id provided. Instead, let's update it to reflect what it's about (use already prepared template).

Applied for next, thanks!

Kind regards
Uffe

Quoted 33 lines
---
 drivers/mmc/core/slot-gpio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/mmc/core/slot-gpio.c +8 -1
index e365d328f43c..dd2a4b6ab6ad 100644
@@ -178,6 +178,10 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id,
        if (IS_ERR(desc))
                return PTR_ERR(desc);
 
+       /* Update default label if no con_id provided */
+       if (!con_id)
+               gpiod_set_consumer_name(desc, ctx->cd_label);
+
        if (debounce) {
                ret = gpiod_set_debounce(desc, debounce);
                if (ret < 0)
@@ -226,6 +230,10 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id,
        if (IS_ERR(desc))
                return PTR_ERR(desc);
 
+       /* Update default label if no con_id provided */
+       if (!con_id)
+               gpiod_set_consumer_name(desc, ctx->ro_label);
+
        if (debounce) {
                ret = gpiod_set_debounce(desc, debounce);
                if (ret < 0)
--

2.33.0

#3 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

Refactor mmc_gpio_alloc() to drop unneeded indentation level and double condition. This increases readability of the code.

Applied for next, thanks!

Kind regards
Uffe

Quoted 53 lines
---
 drivers/mmc/core/slot-gpio.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/mmc/core/slot-gpio.c +17 -18
index 05e907451df9..e365d328f43c 100644
@@ -39,24 +39,24 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
 
 int mmc_gpio_alloc(struct mmc_host *host)
 {
-       struct mmc_gpio *ctx = devm_kzalloc(host->parent,
-                                           sizeof(*ctx), GFP_KERNEL);
-
-       if (ctx) {
-               ctx->cd_debounce_delay_ms = 200;
-               ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL,
-                               "%s cd", dev_name(host->parent));
-               if (!ctx->cd_label)
-                       return -ENOMEM;
-               ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL,
-                               "%s ro", dev_name(host->parent));
-               if (!ctx->ro_label)
-                       return -ENOMEM;
-               host->slot.handler_priv = ctx;
-               host->slot.cd_irq = -EINVAL;
-       }
+       const char *devname = dev_name(host->parent);
+       struct mmc_gpio *ctx;
+
+       ctx = devm_kzalloc(host->parent, sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       ctx->cd_debounce_delay_ms = 200;
+       ctx->cd_label = devm_kasprintf(host->parent, GFP_KERNEL, "%s cd", devname);
+       if (!ctx->cd_label)
+               return -ENOMEM;
+       ctx->ro_label = devm_kasprintf(host->parent, GFP_KERNEL, "%s ro", devname);
+       if (!ctx->ro_label)
+               return -ENOMEM;
+       host->slot.handler_priv = ctx;
+       host->slot.cd_irq = -EINVAL;
 
-       return ctx ? 0 : -ENOMEM;
+       return 0;
 }
 
 int mmc_gpio_get_ro(struct mmc_host *host)
--

2.33.0