Skip to content

Commit

Permalink
at86rf230: copy pdata to driver allocated space
Browse files Browse the repository at this point in the history
This patch copies the platform data in driver allocated space at first.
With this change we ensure that we access the allocated platform data as
readonly space.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Alexander Aring authored and Marcel Holtmann committed Feb 27, 2015
1 parent 9391976 commit aaa1c4d
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions drivers/net/ieee802154/at86rf230.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,24 +1377,24 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0);
}

static struct at86rf230_platform_data *
at86rf230_get_pdata(struct spi_device *spi)
static int
at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr)
{
struct at86rf230_platform_data *pdata;
struct at86rf230_platform_data *pdata = spi->dev.platform_data;

if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node)
return spi->dev.platform_data;
if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) {
if (!pdata)
return -ENOENT;

pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
goto done;
*rstn = pdata->rstn;
*slp_tr = pdata->slp_tr;
return 0;
}

pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
*rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
*slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);

spi->dev.platform_data = pdata;
done:
return pdata;
return 0;
}

static int
Expand Down Expand Up @@ -1501,43 +1501,42 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)

static int at86rf230_probe(struct spi_device *spi)
{
struct at86rf230_platform_data *pdata;
struct ieee802154_hw *hw;
struct at86rf230_local *lp;
unsigned int status;
int rc, irq_type;
int rc, irq_type, rstn, slp_tr;

if (!spi->irq) {
dev_err(&spi->dev, "no IRQ specified\n");
return -EINVAL;
}

pdata = at86rf230_get_pdata(spi);
if (!pdata) {
dev_err(&spi->dev, "no platform_data\n");
return -EINVAL;
rc = at86rf230_get_pdata(spi, &rstn, &slp_tr);
if (rc < 0) {
dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc);
return rc;
}

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

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

/* Reset */
if (gpio_is_valid(pdata->rstn)) {
if (gpio_is_valid(rstn)) {
udelay(1);
gpio_set_value(pdata->rstn, 0);
gpio_set_value(rstn, 0);
udelay(1);
gpio_set_value(pdata->rstn, 1);
gpio_set_value(rstn, 1);
usleep_range(120, 240);
}

Expand Down

0 comments on commit aaa1c4d

Please sign in to comment.