Skip to content

Commit

Permalink
at86rf230: use devm_gpio_request_one
Browse files Browse the repository at this point in the history
This patch replace the gpio_request functions with devm_gpio_request_one
functions. Then we don't need to take care about freeing gpios.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Alexander Aring authored and David S. Miller committed Apr 26, 2014
1 parent 652355c commit 0679e29
Showing 1 changed file with 12 additions and 41 deletions.
53 changes: 12 additions & 41 deletions drivers/net/ieee802154/at86rf230.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,27 +1074,17 @@ static int at86rf230_probe(struct spi_device *spi)
}

if (gpio_is_valid(pdata->rstn)) {
rc = gpio_request(pdata->rstn, "rstn");
rc = devm_gpio_request_one(&spi->dev, pdata->rstn,
GPIOF_OUT_INIT_HIGH, "rstn");
if (rc)
return rc;
}

if (gpio_is_valid(pdata->slp_tr)) {
rc = gpio_request(pdata->slp_tr, "slp_tr");
rc = devm_gpio_request_one(&spi->dev, pdata->slp_tr,
GPIOF_OUT_INIT_LOW, "slp_tr");
if (rc)
goto err_slp_tr;
}

if (gpio_is_valid(pdata->rstn)) {
rc = gpio_direction_output(pdata->rstn, 1);
if (rc)
goto err_gpio_dir;
}

if (gpio_is_valid(pdata->slp_tr)) {
rc = gpio_direction_output(pdata->slp_tr, 0);
if (rc)
goto err_gpio_dir;
return rc;
}

/* Reset */
Expand All @@ -1108,13 +1098,12 @@ static int at86rf230_probe(struct spi_device *spi)

rc = __at86rf230_detect_device(spi, &man_id, &part, &version);
if (rc < 0)
goto err_gpio_dir;
return rc;

if (man_id != 0x001f) {
dev_err(&spi->dev, "Non-Atmel dev found (MAN_ID %02x %02x)\n",
man_id >> 8, man_id & 0xFF);
rc = -EINVAL;
goto err_gpio_dir;
return -EINVAL;
}

switch (part) {
Expand All @@ -1141,16 +1130,12 @@ static int at86rf230_probe(struct spi_device *spi)
}

dev_info(&spi->dev, "Detected %s chip version %d\n", chip, version);
if (!ops) {
rc = -ENOTSUPP;
goto err_gpio_dir;
}
if (!ops)
return -ENOTSUPP;

dev = ieee802154_alloc_device(sizeof(*lp), ops);
if (!dev) {
rc = -ENOMEM;
goto err_gpio_dir;
}
if (!dev)
return -ENOMEM;

lp = dev->priv;
lp->dev = dev;
Expand Down Expand Up @@ -1212,35 +1197,21 @@ static int at86rf230_probe(struct spi_device *spi)
mutex_destroy(&lp->bmux);
ieee802154_free_device(lp->dev);

err_gpio_dir:
if (gpio_is_valid(pdata->slp_tr))
gpio_free(pdata->slp_tr);
err_slp_tr:
if (gpio_is_valid(pdata->rstn))
gpio_free(pdata->rstn);
return rc;
}

static int at86rf230_remove(struct spi_device *spi)
{
struct at86rf230_local *lp = spi_get_drvdata(spi);
struct at86rf230_platform_data *pdata = spi->dev.platform_data;

/* mask all at86rf230 irq's */
at86rf230_write_subreg(lp, SR_IRQ_MASK, 0);
ieee802154_unregister_device(lp->dev);

flush_work(&lp->irqwork);

if (gpio_is_valid(pdata->slp_tr))
gpio_free(pdata->slp_tr);
if (gpio_is_valid(pdata->rstn))
gpio_free(pdata->rstn);

mutex_destroy(&lp->bmux);
ieee802154_free_device(lp->dev);

dev_dbg(&spi->dev, "unregistered at86rf230\n");

return 0;
}

Expand Down

0 comments on commit 0679e29

Please sign in to comment.