text
stringlengths 213
7.14k
| idx
int64 16
12.5k
|
---|---|
--- initial
+++ final
@@ -1,12 +1,9 @@
static int bq24257_irq_probe(struct bq24257_device *bq) {
- int ret;
struct gpio_desc *stat_irq;
- stat_irq = devm_gpiod_get_index(bq->dev, BQ24257_STAT_IRQ, 0);
+ stat_irq = devm_gpiod_get_index(bq->dev, BQ24257_STAT_IRQ, 0, GPIOD_IN);
if (IS_ERR(stat_irq)) {
dev_err(bq->dev, "could not probe stat_irq pin\n");
return PTR_ERR(stat_irq);
}
- ret = gpiod_direction_input(stat_irq);
- if (ret < 0) return ret;
return gpiod_to_irq(stat_irq);
}<sep>@@
expression e1,e2,e3,gpio,ret;
statement S;
@@
- gpio = devm_gpiod_get_index(e1, e2, e3);
+ gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
...
- ret = gpiod_direction_input(gpio);
- if (\(ret\|ret < 0\)) S
@@
identifier ret;
@@
(
- int ret;
... when exists
devm_gpiod_get_index(...)
... when any
&
int ret;
... when != ret
when strict
)
<|end_of_text|> | 282 |
--- initial
+++ final
@@ -1,8 +1,8 @@
static int bq24257_pg_gpio_probe(struct bq24257_device *bq) {
- bq->pg = devm_gpiod_get_index(bq->dev, BQ24257_PG_GPIO, 0);
+ bq->pg = devm_gpiod_get_index(bq->dev, BQ24257_PG_GPIO, 0, GPIOD_IN);
if (IS_ERR(bq->pg)) {
dev_err(bq->dev, "could not probe PG pin\n");
return PTR_ERR(bq->pg);
}
- return gpiod_direction_input(bq->pg);
+ return 0;
}<sep>@@
expression e1,e2,e3,gpio;
@@
- gpio = devm_gpiod_get_index(e1, e2, e3);
+ gpio = devm_gpiod_get_index(e1, e2, e3, GPIOD_IN);
...
- return gpiod_direction_input(gpio);
+ return 0;
<|end_of_text|> | 283 |
--- initial
+++ final
@@ -1,30 +1,20 @@
static int edp_gpio_config(struct edp_ctrl *ctrl) {
struct device *dev = &ctrl->pdev->dev;
int ret;
- ctrl->panel_hpd_gpio = devm_gpiod_get(dev, "panel-hpd");
+ ctrl->panel_hpd_gpio = devm_gpiod_get(dev, "panel-hpd", GPIOD_IN);
if (IS_ERR(ctrl->panel_hpd_gpio)) {
ret = PTR_ERR(ctrl->panel_hpd_gpio);
ctrl->panel_hpd_gpio = NULL;
pr_err("%s: cannot get panel-hpd-gpios, %d\n", __func__, ret);
return ret;
}
- ret = gpiod_direction_input(ctrl->panel_hpd_gpio);
- if (ret) {
- pr_err("%s: Set direction for hpd failed, %d\n", __func__, ret);
- return ret;
- }
- ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en");
+ ctrl->panel_en_gpio = devm_gpiod_get(dev, "panel-en", GPIOD_OUT_LOW);
if (IS_ERR(ctrl->panel_en_gpio)) {
ret = PTR_ERR(ctrl->panel_en_gpio);
ctrl->panel_en_gpio = NULL;
pr_err("%s: cannot get panel-en-gpios, %d\n", __func__, ret);
return ret;
}
- ret = gpiod_direction_output(ctrl->panel_en_gpio, 0);
- if (ret) {
- pr_err("%s: Set direction for panel_en failed, %d\n", __func__, ret);
- return ret;
- }
DBG("gpio on");
return 0;
}<sep>@@
expression e1,e2,gpio,ret;
statement S;
@@
- gpio = devm_gpiod_get(e1, e2);
+ gpio = devm_gpiod_get(e1, e2, GPIOD_IN);
...
- ret = gpiod_direction_input(gpio);
- if (\(ret\|ret < 0\)) S
@@
expression e1,e2,gpio,ret;
statement S;
@@
- gpio = devm_gpiod_get(e1, e2);
+ gpio = devm_gpiod_get(e1, e2, GPIOD_OUT_LOW);
...
- ret = gpiod_direction_output(gpio, 0);
- if (\(ret\|ret < 0\)) S
<|end_of_text|> | 284 |
--- initial
+++ final
@@ -1,84 +1,82 @@
static int mxs_lradc_probe(struct platform_device *pdev) {
const struct of_device_id *of_id = of_match_device(mxs_lradc_dt_ids, &pdev->dev);
const struct mxs_lradc_of_config *of_cfg = &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
struct device *dev = &pdev->dev;
struct device_node *node = dev->of_node;
struct mxs_lradc *lradc;
struct iio_dev *iio;
struct resource *iores;
uint32_t ts_wires = 0;
int ret = 0;
int i;
/* Allocate the IIO device. */
- iio = iio_device_alloc(sizeof(*lradc));
+ iio = devm_iio_device_alloc(dev, sizeof(*lradc));
if (!iio) {
dev_err(dev, "Failed to allocate IIO device\n");
return -ENOMEM;
}
lradc = iio_priv(iio);
/* Grab the memory area */
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
lradc->dev = &pdev->dev;
lradc->base = devm_ioremap_resource(dev, iores);
if (IS_ERR(lradc->base)) {
ret = PTR_ERR(lradc->base);
- goto err_addr;
+ return ret;
}
INIT_WORK(&lradc->ts_work, mxs_lradc_ts_work);
/* Check if touchscreen is enabled in DT. */
ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires", &ts_wires);
if (ret)
dev_info(dev, "Touchscreen not enabled.\n");
else if (ts_wires == 4)
lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_4WIRE;
else if (ts_wires == 5)
lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_5WIRE;
else
dev_warn(dev, "Unsupported number of touchscreen wires (%d)\n", ts_wires);
/* Grab all IRQ sources */
for (i = 0; i < of_cfg->irq_count; i++) {
lradc->irq[i] = platform_get_irq(pdev, i);
if (lradc->irq[i] < 0) {
ret = -EINVAL;
- goto err_addr;
+ return ret;
}
ret = devm_request_irq(dev, lradc->irq[i], mxs_lradc_handle_irq, 0, of_cfg->irq_name[i], iio);
- if (ret) goto err_addr;
+ if (ret) return ret;
}
platform_set_drvdata(pdev, iio);
init_completion(&lradc->completion);
mutex_init(&lradc->lock);
iio->name = pdev->name;
iio->dev.parent = &pdev->dev;
iio->info = &mxs_lradc_iio_info;
iio->modes = INDIO_DIRECT_MODE;
iio->channels = mxs_lradc_chan_spec;
iio->num_channels = ARRAY_SIZE(mxs_lradc_chan_spec);
iio->masklength = LRADC_MAX_TOTAL_CHANS;
ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time, &mxs_lradc_trigger_handler, &mxs_lradc_buffer_ops);
- if (ret) goto err_addr;
+ if (ret) return ret;
ret = mxs_lradc_trigger_init(iio);
if (ret) goto err_trig;
/* Configure the hardware. */
ret = mxs_lradc_hw_init(lradc);
if (ret) goto err_dev;
/* Register the touchscreen input device. */
ret = mxs_lradc_ts_register(lradc);
if (ret) goto err_dev;
/* Register IIO device. */
ret = iio_device_register(iio);
if (ret) {
dev_err(dev, "Failed to register IIO device\n");
goto err_ts;
}
return 0;
err_ts:
mxs_lradc_ts_unregister(lradc);
err_dev:
mxs_lradc_trigger_remove(iio);
err_trig:
iio_triggered_buffer_cleanup(iio);
-err_addr:
- iio_device_free(iio);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,dev;
@@
struct device *dev;
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
<|end_of_text|> | 285 |
--- initial
+++ final
@@ -1,87 +1,83 @@
static int spear_adc_probe(struct platform_device *pdev) {
struct device_node *np = pdev->dev.of_node;
struct device *dev = &pdev->dev;
struct spear_adc_info *info;
struct iio_dev *iodev = NULL;
int ret = -ENODEV;
int irq;
- iodev = iio_device_alloc(sizeof(struct spear_adc_info));
+ iodev = devm_iio_device_alloc(dev, sizeof(struct spear_adc_info));
if (!iodev) {
dev_err(dev, "failed allocating iio device\n");
- ret = -ENOMEM;
- goto errout1;
+ return -ENOMEM;
}
info = iio_priv(iodev);
info->np = np;
/*
* SPEAr600 has a different register layout than other SPEAr SoC's
* (e.g. SPEAr3xx). Let's provide two register base addresses
* to support multi-arch kernels.
*/
info->adc_base_spear6xx = of_iomap(np, 0);
if (!info->adc_base_spear6xx) {
dev_err(dev, "failed mapping memory\n");
ret = -ENOMEM;
- goto errout2;
+ return ret;
}
info->adc_base_spear3xx = (struct adc_regs_spear3xx *)info->adc_base_spear6xx;
info->clk = clk_get(dev, NULL);
if (IS_ERR(info->clk)) {
dev_err(dev, "failed getting clock\n");
goto errout3;
}
ret = clk_prepare_enable(info->clk);
if (ret) {
dev_err(dev, "failed enabling clock\n");
goto errout4;
}
irq = platform_get_irq(pdev, 0);
if ((irq < 0) || (irq >= NR_IRQS)) {
dev_err(dev, "failed getting interrupt resource\n");
ret = -EINVAL;
goto errout5;
}
ret = devm_request_irq(dev, irq, spear_adc_isr, 0, MOD_NAME, info);
if (ret < 0) {
dev_err(dev, "failed requesting interrupt\n");
goto errout5;
}
if (of_property_read_u32(np, "sampling-frequency", &info->sampling_freq)) {
dev_err(dev, "sampling-frequency missing in DT\n");
ret = -EINVAL;
goto errout5;
}
/*
* Optional avg_samples defaults to 0, resulting in single data
* conversion
*/
of_property_read_u32(np, "average-samples", &info->avg_samples);
/*
* Optional vref_external defaults to 0, resulting in internal vref
* selection
*/
of_property_read_u32(np, "vref-external", &info->vref_external);
spear_adc_configure(info);
platform_set_drvdata(pdev, iodev);
init_completion(&info->completion);
iodev->name = MOD_NAME;
iodev->dev.parent = dev;
iodev->info = &spear_adc_iio_info;
iodev->modes = INDIO_DIRECT_MODE;
iodev->channels = spear_adc_iio_channels;
iodev->num_channels = ARRAY_SIZE(spear_adc_iio_channels);
ret = iio_device_register(iodev);
if (ret) goto errout5;
dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq);
return 0;
errout5:
clk_disable_unprepare(info->clk);
errout4:
clk_put(info->clk);
errout3:
iounmap(info->adc_base_spear6xx);
-errout2:
- iio_device_free(iodev);
-errout1:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,dev;
@@
struct device *dev;
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
<|end_of_text|> | 286 |
--- initial
+++ final
@@ -1,88 +1,86 @@
static int exynos_adc_probe(struct platform_device *pdev) {
struct exynos_adc *info = NULL;
struct device_node *np = pdev->dev.of_node;
struct iio_dev *indio_dev = NULL;
struct resource *mem;
int ret = -ENODEV;
int irq;
if (!np) return ret;
- indio_dev = iio_device_alloc(sizeof(struct exynos_adc));
+ indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(struct exynos_adc));
if (!indio_dev) {
dev_err(&pdev->dev, "failed allocating iio device\n");
return -ENOMEM;
}
info = iio_priv(indio_dev);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
info->regs = devm_ioremap_resource(&pdev->dev, mem);
if (IS_ERR(info->regs)) {
ret = PTR_ERR(info->regs);
- goto err_iio;
+ return ret;
}
mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
info->enable_reg = devm_ioremap_resource(&pdev->dev, mem);
if (IS_ERR(info->enable_reg)) {
ret = PTR_ERR(info->enable_reg);
- goto err_iio;
+ return ret;
}
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
dev_err(&pdev->dev, "no irq resource?\n");
ret = irq;
- goto err_iio;
+ return ret;
}
info->irq = irq;
init_completion(&info->completion);
ret = request_irq(info->irq, exynos_adc_isr, 0, dev_name(&pdev->dev), info);
if (ret < 0) {
dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", info->irq);
- goto err_iio;
+ return ret;
}
writel(1, info->enable_reg);
info->clk = devm_clk_get(&pdev->dev, "adc");
if (IS_ERR(info->clk)) {
dev_err(&pdev->dev, "failed getting clock, err = %ld\n", PTR_ERR(info->clk));
ret = PTR_ERR(info->clk);
goto err_irq;
}
info->vdd = devm_regulator_get(&pdev->dev, "vdd");
if (IS_ERR(info->vdd)) {
dev_err(&pdev->dev, "failed getting regulator, err = %ld\n", PTR_ERR(info->vdd));
ret = PTR_ERR(info->vdd);
goto err_irq;
}
info->version = exynos_adc_get_version(pdev);
platform_set_drvdata(pdev, indio_dev);
indio_dev->name = dev_name(&pdev->dev);
indio_dev->dev.parent = &pdev->dev;
indio_dev->dev.of_node = pdev->dev.of_node;
indio_dev->info = &exynos_adc_iio_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = exynos_adc_iio_channels;
if (info->version == ADC_V1)
indio_dev->num_channels = MAX_ADC_V1_CHANNELS;
else
indio_dev->num_channels = MAX_ADC_V2_CHANNELS;
ret = iio_device_register(indio_dev);
if (ret) goto err_irq;
ret = regulator_enable(info->vdd);
if (ret) goto err_iio_dev;
clk_prepare_enable(info->clk);
exynos_adc_hw_init(info);
ret = of_platform_populate(np, exynos_adc_match, NULL, &pdev->dev);
if (ret < 0) {
dev_err(&pdev->dev, "failed adding child nodes\n");
goto err_of_populate;
}
return 0;
err_of_populate:
device_for_each_child(&pdev->dev, NULL, exynos_adc_remove_devices);
regulator_disable(info->vdd);
clk_disable_unprepare(info->clk);
err_iio_dev:
iio_device_unregister(indio_dev);
err_irq:
free_irq(info->irq, info);
-err_iio:
- iio_device_free(indio_dev);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@
f(T x) {
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(&x->dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
}<|end_of_text|> | 287 |
--- initial
+++ final
@@ -1,141 +1,135 @@
static int at91_adc_probe(struct platform_device *pdev) {
unsigned int prsc, mstrclk, ticks, adc_clk, shtim;
int ret;
struct iio_dev *idev;
struct at91_adc_state *st;
struct resource *res;
u32 reg;
- idev = iio_device_alloc(sizeof(struct at91_adc_state));
- if (idev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ idev = devm_iio_device_alloc(dev, sizeof(struct at91_adc_state));
+ if (idev == NULL) return -ENOMEM;
st = iio_priv(idev);
if (pdev->dev.of_node)
ret = at91_adc_probe_dt(st, pdev);
else
ret = at91_adc_probe_pdata(st, pdev);
if (ret) {
dev_err(&pdev->dev, "No platform data available.\n");
ret = -EINVAL;
- goto error_free_device;
+ return ret;
}
platform_set_drvdata(pdev, idev);
idev->dev.parent = &pdev->dev;
idev->name = dev_name(&pdev->dev);
idev->modes = INDIO_DIRECT_MODE;
idev->info = &at91_adc_info;
st->irq = platform_get_irq(pdev, 0);
if (st->irq < 0) {
dev_err(&pdev->dev, "No IRQ ID is designated\n");
ret = -ENODEV;
- goto error_free_device;
+ return ret;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
st->reg_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(st->reg_base)) {
ret = PTR_ERR(st->reg_base);
- goto error_free_device;
+ return ret;
}
/*
* Disable all IRQs before setting up the handler
*/
at91_adc_writel(st, AT91_ADC_CR, AT91_ADC_SWRST);
at91_adc_writel(st, AT91_ADC_IDR, 0xFFFFFFFF);
ret = request_irq(st->irq, at91_adc_eoc_trigger, 0, pdev->dev.driver->name, idev);
if (ret) {
dev_err(&pdev->dev, "Failed to allocate IRQ.\n");
- goto error_free_device;
+ return ret;
}
st->clk = devm_clk_get(&pdev->dev, "adc_clk");
if (IS_ERR(st->clk)) {
dev_err(&pdev->dev, "Failed to get the clock.\n");
ret = PTR_ERR(st->clk);
goto error_free_irq;
}
ret = clk_prepare_enable(st->clk);
if (ret) {
dev_err(&pdev->dev, "Could not prepare or enable the clock.\n");
goto error_free_irq;
}
st->adc_clk = devm_clk_get(&pdev->dev, "adc_op_clk");
if (IS_ERR(st->adc_clk)) {
dev_err(&pdev->dev, "Failed to get the ADC clock.\n");
ret = PTR_ERR(st->adc_clk);
goto error_disable_clk;
}
ret = clk_prepare_enable(st->adc_clk);
if (ret) {
dev_err(&pdev->dev, "Could not prepare or enable the ADC clock.\n");
goto error_disable_clk;
}
/*
* Prescaler rate computation using the formula from the Atmel's
* datasheet : ADC Clock = MCK / ((Prescaler + 1) * 2), ADC Clock being
* specified by the electrical characteristics of the board.
*/
mstrclk = clk_get_rate(st->clk);
adc_clk = clk_get_rate(st->adc_clk);
prsc = (mstrclk / (2 * adc_clk)) - 1;
if (!st->startup_time) {
dev_err(&pdev->dev, "No startup time available.\n");
ret = -EINVAL;
goto error_disable_adc_clk;
}
/*
* Number of ticks needed to cover the startup time of the ADC as
* defined in the electrical characteristics of the board, divided by 8.
* The formula thus is : Startup Time = (ticks + 1) * 8 / ADC Clock
*/
ticks = round_up((st->startup_time * adc_clk / 1000000) - 1, 8) / 8;
/*
* a minimal Sample and Hold Time is necessary for the ADC to guarantee
* the best converted final value between two channels selection
* The formula thus is : Sample and Hold Time = (shtim + 1) / ADCClock
*/
shtim = round_up((st->sample_hold_time * adc_clk / 1000000) - 1, 1);
reg = AT91_ADC_PRESCAL_(prsc) & AT91_ADC_PRESCAL;
reg |= AT91_ADC_STARTUP_(ticks) & AT91_ADC_STARTUP;
if (st->low_res) reg |= AT91_ADC_LOWRES;
if (st->sleep_mode) reg |= AT91_ADC_SLEEP;
reg |= AT91_ADC_SHTIM_(shtim) & AT91_ADC_SHTIM;
at91_adc_writel(st, AT91_ADC_MR, reg);
/* Setup the ADC channels available on the board */
ret = at91_adc_channel_init(idev);
if (ret < 0) {
dev_err(&pdev->dev, "Couldn't initialize the channels.\n");
goto error_disable_adc_clk;
}
init_waitqueue_head(&st->wq_data_avail);
mutex_init(&st->lock);
ret = at91_adc_buffer_init(idev);
if (ret < 0) {
dev_err(&pdev->dev, "Couldn't initialize the buffer.\n");
goto error_disable_adc_clk;
}
ret = at91_adc_trigger_init(idev);
if (ret < 0) {
dev_err(&pdev->dev, "Couldn't setup the triggers.\n");
goto error_unregister_buffer;
}
ret = iio_device_register(idev);
if (ret < 0) {
dev_err(&pdev->dev, "Couldn't register the device.\n");
goto error_remove_triggers;
}
return 0;
error_remove_triggers:
at91_adc_trigger_remove(idev);
error_unregister_buffer:
at91_adc_buffer_remove(idev);
error_disable_adc_clk:
clk_disable_unprepare(st->adc_clk);
error_disable_clk:
clk_disable_unprepare(st->clk);
error_free_irq:
free_irq(st->irq, idev);
-error_free_device:
- iio_device_free(idev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 288 |
--- initial
+++ final
@@ -1,30 +1,24 @@
static int kxsd9_probe(struct spi_device *spi) {
struct iio_dev *indio_dev;
struct kxsd9_state *st;
int ret;
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
st->us = spi;
mutex_init(&st->buf_lock);
indio_dev->channels = kxsd9_channels;
indio_dev->num_channels = ARRAY_SIZE(kxsd9_channels);
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &kxsd9_info;
indio_dev->modes = INDIO_DIRECT_MODE;
spi->mode = SPI_MODE_0;
spi_setup(spi);
kxsd9_power_up(st);
ret = iio_device_register(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
return 0;
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 289 |
--- initial
+++ final
@@ -1,76 +1,70 @@
static int hid_accel_3d_probe(struct platform_device *pdev) {
int ret = 0;
static const char *name = "accel_3d";
struct iio_dev *indio_dev;
struct accel_3d_state *accel_state;
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_chan_spec *channels;
- indio_dev = iio_device_alloc(sizeof(struct accel_3d_state));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(struct accel_3d_state));
+ if (indio_dev == NULL) return -ENOMEM;
platform_set_drvdata(pdev, indio_dev);
accel_state = iio_priv(indio_dev);
accel_state->common_attributes.hsdev = hsdev;
accel_state->common_attributes.pdev = pdev;
ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_ACCEL_3D, &accel_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n");
- goto error_free_dev;
+ return ret;
}
channels = kmemdup(accel_3d_channels, sizeof(accel_3d_channels), GFP_KERNEL);
if (!channels) {
ret = -ENOMEM;
dev_err(&pdev->dev, "failed to duplicate channels\n");
- goto error_free_dev;
+ return ret;
}
ret = accel_3d_parse_report(pdev, hsdev, channels, HID_USAGE_SENSOR_ACCEL_3D, accel_state);
if (ret) {
dev_err(&pdev->dev, "failed to setup attributes\n");
goto error_free_dev_mem;
}
indio_dev->channels = channels;
indio_dev->num_channels = ARRAY_SIZE(accel_3d_channels);
indio_dev->dev.parent = &pdev->dev;
indio_dev->info = &accel_3d_info;
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, NULL, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem;
}
accel_state->common_attributes.data_ready = false;
ret = hid_sensor_setup_trigger(indio_dev, name, &accel_state->common_attributes);
if (ret < 0) {
dev_err(&pdev->dev, "trigger setup failed\n");
goto error_unreg_buffer_funcs;
}
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&pdev->dev, "device register failed\n");
goto error_remove_trigger;
}
accel_state->callbacks.send_event = accel_3d_proc_event;
accel_state->callbacks.capture_sample = accel_3d_capture_sample;
accel_state->callbacks.pdev = pdev;
ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D, &accel_state->callbacks);
if (ret < 0) {
dev_err(&pdev->dev, "callback reg failed\n");
goto error_iio_unreg;
}
return ret;
error_iio_unreg:
iio_device_unregister(indio_dev);
error_remove_trigger:
hid_sensor_remove_trigger(indio_dev);
error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem:
kfree(indio_dev->channels);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 290 |
--- initial
+++ final
@@ -1,20 +1,14 @@
static int st_accel_spi_probe(struct spi_device *spi) {
struct iio_dev *indio_dev;
struct st_sensor_data *adata;
int err;
- indio_dev = iio_device_alloc(sizeof(*adata));
- if (indio_dev == NULL) {
- err = -ENOMEM;
- goto iio_device_alloc_error;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*adata));
+ if (indio_dev == NULL) return -ENOMEM;
adata = iio_priv(indio_dev);
adata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, adata);
err = st_accel_common_probe(indio_dev, spi->dev.platform_data);
- if (err < 0) goto st_accel_common_probe_error;
+ if (err < 0) return err;
return 0;
-st_accel_common_probe_error:
- iio_device_free(indio_dev);
-iio_device_alloc_error:
return err;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 291 |
--- initial
+++ final
@@ -1,44 +1,40 @@
static int tiadc_probe(struct platform_device *pdev) {
struct iio_dev *indio_dev;
struct tiadc_device *adc_dev;
struct device_node *node = pdev->dev.of_node;
struct property *prop;
const __be32 *cur;
int err;
u32 val;
int channels = 0;
if (!node) {
dev_err(&pdev->dev, "Could not find valid DT data.\n");
return -EINVAL;
}
- indio_dev = iio_device_alloc(sizeof(struct tiadc_device));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(struct tiadc_device));
if (indio_dev == NULL) {
dev_err(&pdev->dev, "failed to allocate iio device\n");
- err = -ENOMEM;
- goto err_ret;
+ return -ENOMEM;
}
adc_dev = iio_priv(indio_dev);
adc_dev->mfd_tscadc = ti_tscadc_dev_get(pdev);
of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
adc_dev->channel_line[channels] = val;
channels++;
}
adc_dev->channels = channels;
indio_dev->dev.parent = &pdev->dev;
indio_dev->name = dev_name(&pdev->dev);
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &tiadc_info;
tiadc_step_config(adc_dev);
err = tiadc_channel_init(indio_dev, adc_dev->channels);
- if (err < 0) goto err_free_device;
+ if (err < 0) return err;
err = iio_device_register(indio_dev);
if (err) goto err_free_channels;
platform_set_drvdata(pdev, indio_dev);
return 0;
err_free_channels:
tiadc_channels_remove(indio_dev);
-err_free_device:
- iio_device_free(indio_dev);
-err_ret:
return err;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 292 |
--- initial
+++ final
@@ -1,30 +1,28 @@
static int vprbrd_adc_probe(struct platform_device *pdev) {
struct vprbrd *vb = dev_get_drvdata(pdev->dev.parent);
struct vprbrd_adc *adc;
struct iio_dev *indio_dev;
int ret;
/* registering iio */
- indio_dev = iio_device_alloc(sizeof(*adc));
+ indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc));
if (!indio_dev) {
dev_err(&pdev->dev, "failed allocating iio device\n");
return -ENOMEM;
}
adc = iio_priv(indio_dev);
adc->vb = vb;
indio_dev->name = "viperboard adc";
indio_dev->dev.parent = &pdev->dev;
indio_dev->info = &vprbrd_adc_iio_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = vprbrd_adc_iio_channels;
indio_dev->num_channels = ARRAY_SIZE(vprbrd_adc_iio_channels);
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&pdev->dev, "could not register iio (adc)");
- goto error;
+ return ret;
}
platform_set_drvdata(pdev, indio_dev);
return 0;
-error:
- iio_device_free(indio_dev);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@
f(T x) {
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(&x->dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
}<|end_of_text|> | 293 |
--- initial
+++ final
@@ -1,20 +1,14 @@
static int st_press_spi_probe(struct spi_device *spi) {
struct iio_dev *indio_dev;
struct st_sensor_data *pdata;
int err;
- indio_dev = iio_device_alloc(sizeof(*pdata));
- if (indio_dev == NULL) {
- err = -ENOMEM;
- goto iio_device_alloc_error;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*pdata));
+ if (indio_dev == NULL) return -ENOMEM;
pdata = iio_priv(indio_dev);
pdata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, pdata);
err = st_press_common_probe(indio_dev, spi->dev.platform_data);
- if (err < 0) goto st_press_common_probe_error;
+ if (err < 0) return err;
return 0;
-st_press_common_probe_error:
- iio_device_free(indio_dev);
-iio_device_alloc_error:
return err;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 294 |
--- initial
+++ final
@@ -1,34 +1,32 @@
static int adis16480_probe(struct spi_device *spi) {
const struct spi_device_id *id = spi_get_device_id(spi);
struct iio_dev *indio_dev;
struct adis16480 *st;
int ret;
- indio_dev = iio_device_alloc(sizeof(*st));
+ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (indio_dev == NULL) return -ENOMEM;
spi_set_drvdata(spi, indio_dev);
st = iio_priv(indio_dev);
st->chip_info = &adis16480_chip_info[id->driver_data];
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->channels = st->chip_info->channels;
indio_dev->num_channels = st->chip_info->num_channels;
indio_dev->info = &adis16480_info;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(&st->adis, indio_dev, spi, &adis16480_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis16480_initial_setup(indio_dev);
if (ret) goto error_cleanup_buffer;
ret = iio_device_register(indio_dev);
if (ret) goto error_stop_device;
adis16480_debugfs_init(indio_dev);
return 0;
error_stop_device:
adis16480_stop_device(indio_dev);
error_cleanup_buffer:
adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@
f(T x) {
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(&x->dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
}<|end_of_text|> | 295 |
--- initial
+++ final
@@ -1,76 +1,70 @@
static int hid_als_probe(struct platform_device *pdev) {
int ret = 0;
static const char *name = "als";
struct iio_dev *indio_dev;
struct als_state *als_state;
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_chan_spec *channels;
- indio_dev = iio_device_alloc(sizeof(struct als_state));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(struct als_state));
+ if (indio_dev == NULL) return -ENOMEM;
platform_set_drvdata(pdev, indio_dev);
als_state = iio_priv(indio_dev);
als_state->common_attributes.hsdev = hsdev;
als_state->common_attributes.pdev = pdev;
ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_ALS, &als_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n");
- goto error_free_dev;
+ return ret;
}
channels = kmemdup(als_channels, sizeof(als_channels), GFP_KERNEL);
if (!channels) {
ret = -ENOMEM;
dev_err(&pdev->dev, "failed to duplicate channels\n");
- goto error_free_dev;
+ return ret;
}
ret = als_parse_report(pdev, hsdev, channels, HID_USAGE_SENSOR_ALS, als_state);
if (ret) {
dev_err(&pdev->dev, "failed to setup attributes\n");
goto error_free_dev_mem;
}
indio_dev->channels = channels;
indio_dev->num_channels = ARRAY_SIZE(als_channels);
indio_dev->dev.parent = &pdev->dev;
indio_dev->info = &als_info;
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, NULL, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem;
}
als_state->common_attributes.data_ready = false;
ret = hid_sensor_setup_trigger(indio_dev, name, &als_state->common_attributes);
if (ret < 0) {
dev_err(&pdev->dev, "trigger setup failed\n");
goto error_unreg_buffer_funcs;
}
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&pdev->dev, "device register failed\n");
goto error_remove_trigger;
}
als_state->callbacks.send_event = als_proc_event;
als_state->callbacks.capture_sample = als_capture_sample;
als_state->callbacks.pdev = pdev;
ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_ALS, &als_state->callbacks);
if (ret < 0) {
dev_err(&pdev->dev, "callback reg failed\n");
goto error_iio_unreg;
}
return ret;
error_iio_unreg:
iio_device_unregister(indio_dev);
error_remove_trigger:
hid_sensor_remove_trigger(indio_dev);
error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem:
kfree(indio_dev->channels);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 296 |
--- initial
+++ final
@@ -1,35 +1,33 @@
static int adis16400_probe(struct spi_device *spi) {
struct adis16400_state *st;
struct iio_dev *indio_dev;
int ret;
- indio_dev = iio_device_alloc(sizeof(*st));
+ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
/* setup the industrialio driver allocated elements */
st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->channels = st->variant->channels;
indio_dev->num_channels = st->variant->num_channels;
indio_dev->info = &adis16400_info;
indio_dev->modes = INDIO_DIRECT_MODE;
if (!(st->variant->flags & ADIS16400_NO_BURST)) indio_dev->available_scan_masks = adis16400_burst_scan_mask;
ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev, adis16400_trigger_handler);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis16400_initial_setup(indio_dev);
if (ret) goto error_cleanup_buffer;
ret = iio_device_register(indio_dev);
if (ret) goto error_cleanup_buffer;
adis16400_debugfs_init(indio_dev);
return 0;
error_cleanup_buffer:
adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@
f(T x) {
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(&x->dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
}<|end_of_text|> | 297 |
--- initial
+++ final
@@ -1,20 +1,14 @@
static int st_magn_spi_probe(struct spi_device *spi) {
struct iio_dev *indio_dev;
struct st_sensor_data *mdata;
int err;
- indio_dev = iio_device_alloc(sizeof(*mdata));
- if (indio_dev == NULL) {
- err = -ENOMEM;
- goto iio_device_alloc_error;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*mdata));
+ if (indio_dev == NULL) return -ENOMEM;
mdata = iio_priv(indio_dev);
mdata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, mdata);
err = st_magn_common_probe(indio_dev, NULL);
- if (err < 0) goto st_magn_common_probe_error;
+ if (err < 0) return err;
return 0;
-st_magn_common_probe_error:
- iio_device_free(indio_dev);
-iio_device_alloc_error:
return err;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 298 |
--- initial
+++ final
@@ -1,76 +1,70 @@
static int hid_magn_3d_probe(struct platform_device *pdev) {
int ret = 0;
static char *name = "magn_3d";
struct iio_dev *indio_dev;
struct magn_3d_state *magn_state;
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_chan_spec *channels;
- indio_dev = iio_device_alloc(sizeof(struct magn_3d_state));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(struct magn_3d_state));
+ if (indio_dev == NULL) return -ENOMEM;
platform_set_drvdata(pdev, indio_dev);
magn_state = iio_priv(indio_dev);
magn_state->common_attributes.hsdev = hsdev;
magn_state->common_attributes.pdev = pdev;
ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_COMPASS_3D, &magn_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n");
- goto error_free_dev;
+ return ret;
}
channels = kmemdup(magn_3d_channels, sizeof(magn_3d_channels), GFP_KERNEL);
if (!channels) {
ret = -ENOMEM;
dev_err(&pdev->dev, "failed to duplicate channels\n");
- goto error_free_dev;
+ return ret;
}
ret = magn_3d_parse_report(pdev, hsdev, channels, HID_USAGE_SENSOR_COMPASS_3D, magn_state);
if (ret) {
dev_err(&pdev->dev, "failed to setup attributes\n");
goto error_free_dev_mem;
}
indio_dev->channels = channels;
indio_dev->num_channels = ARRAY_SIZE(magn_3d_channels);
indio_dev->dev.parent = &pdev->dev;
indio_dev->info = &magn_3d_info;
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, NULL, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem;
}
magn_state->common_attributes.data_ready = false;
ret = hid_sensor_setup_trigger(indio_dev, name, &magn_state->common_attributes);
if (ret < 0) {
dev_err(&pdev->dev, "trigger setup failed\n");
goto error_unreg_buffer_funcs;
}
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&pdev->dev, "device register failed\n");
goto error_remove_trigger;
}
magn_state->callbacks.send_event = magn_3d_proc_event;
magn_state->callbacks.capture_sample = magn_3d_capture_sample;
magn_state->callbacks.pdev = pdev;
ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D, &magn_state->callbacks);
if (ret < 0) {
dev_err(&pdev->dev, "callback reg failed\n");
goto error_iio_unreg;
}
return ret;
error_iio_unreg:
iio_device_unregister(indio_dev);
error_remove_trigger:
hid_sensor_remove_trigger(indio_dev);
error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem:
kfree(indio_dev->channels);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 299 |
--- initial
+++ final
@@ -1,76 +1,70 @@
static int hid_gyro_3d_probe(struct platform_device *pdev) {
int ret = 0;
static const char *name = "gyro_3d";
struct iio_dev *indio_dev;
struct gyro_3d_state *gyro_state;
struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
struct iio_chan_spec *channels;
- indio_dev = iio_device_alloc(sizeof(struct gyro_3d_state));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(struct gyro_3d_state));
+ if (indio_dev == NULL) return -ENOMEM;
platform_set_drvdata(pdev, indio_dev);
gyro_state = iio_priv(indio_dev);
gyro_state->common_attributes.hsdev = hsdev;
gyro_state->common_attributes.pdev = pdev;
ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_GYRO_3D, &gyro_state->common_attributes);
if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n");
- goto error_free_dev;
+ return ret;
}
channels = kmemdup(gyro_3d_channels, sizeof(gyro_3d_channels), GFP_KERNEL);
if (!channels) {
ret = -ENOMEM;
dev_err(&pdev->dev, "failed to duplicate channels\n");
- goto error_free_dev;
+ return ret;
}
ret = gyro_3d_parse_report(pdev, hsdev, channels, HID_USAGE_SENSOR_GYRO_3D, gyro_state);
if (ret) {
dev_err(&pdev->dev, "failed to setup attributes\n");
goto error_free_dev_mem;
}
indio_dev->channels = channels;
indio_dev->num_channels = ARRAY_SIZE(gyro_3d_channels);
indio_dev->dev.parent = &pdev->dev;
indio_dev->info = &gyro_3d_info;
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, NULL, NULL);
if (ret) {
dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
goto error_free_dev_mem;
}
gyro_state->common_attributes.data_ready = false;
ret = hid_sensor_setup_trigger(indio_dev, name, &gyro_state->common_attributes);
if (ret < 0) {
dev_err(&pdev->dev, "trigger setup failed\n");
goto error_unreg_buffer_funcs;
}
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&pdev->dev, "device register failed\n");
goto error_remove_trigger;
}
gyro_state->callbacks.send_event = gyro_3d_proc_event;
gyro_state->callbacks.capture_sample = gyro_3d_capture_sample;
gyro_state->callbacks.pdev = pdev;
ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D, &gyro_state->callbacks);
if (ret < 0) {
dev_err(&pdev->dev, "callback reg failed\n");
goto error_iio_unreg;
}
return ret;
error_iio_unreg:
iio_device_unregister(indio_dev);
error_remove_trigger:
hid_sensor_remove_trigger(indio_dev);
error_unreg_buffer_funcs:
iio_triggered_buffer_cleanup(indio_dev);
error_free_dev_mem:
kfree(indio_dev->channels);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 300 |
--- initial
+++ final
@@ -1,30 +1,24 @@
static int adis16060_r_probe(struct spi_device *spi) {
int ret;
struct adis16060_state *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
st = iio_priv(indio_dev);
st->us_r = spi;
mutex_init(&st->buf_lock);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16060_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = adis16060_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16060_channels);
ret = iio_device_register(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
adis16060_iio_dev = indio_dev;
return 0;
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 301 |
--- initial
+++ final
@@ -1,29 +1,23 @@
static int adis16130_probe(struct spi_device *spi) {
int ret;
struct adis16130_state *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
st->us = spi;
mutex_init(&st->buf_lock);
indio_dev->name = spi->dev.driver->name;
indio_dev->channels = adis16130_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16130_channels);
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16130_info;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
return 0;
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 302 |
--- initial
+++ final
@@ -1,34 +1,28 @@
static int adxrs450_probe(struct spi_device *spi) {
int ret;
struct adxrs450_state *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
st->us = spi;
mutex_init(&st->buf_lock);
/* This is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adxrs450_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = adxrs450_channels[spi_get_device_id(spi)->driver_data];
indio_dev->num_channels = ARRAY_SIZE(adxrs450_channels);
indio_dev->name = spi->dev.driver->name;
ret = iio_device_register(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adxrs450_initial_setup(indio_dev);
if (ret) goto error_initial;
return 0;
error_initial:
iio_device_unregister(indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 303 |
--- initial
+++ final
@@ -1,20 +1,14 @@
static int st_gyro_spi_probe(struct spi_device *spi) {
struct iio_dev *indio_dev;
struct st_sensor_data *gdata;
int err;
- indio_dev = iio_device_alloc(sizeof(*gdata));
- if (indio_dev == NULL) {
- err = -ENOMEM;
- goto iio_device_alloc_error;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*gdata));
+ if (indio_dev == NULL) return -ENOMEM;
gdata = iio_priv(indio_dev);
gdata->dev = &spi->dev;
st_sensors_spi_configure(indio_dev, spi, gdata);
err = st_gyro_common_probe(indio_dev, (struct st_sensors_platform_data *)&gyro_pdata);
- if (err < 0) goto st_gyro_common_probe_error;
+ if (err < 0) return err;
return 0;
-st_gyro_common_probe_error:
- iio_device_free(indio_dev);
-iio_device_alloc_error:
return err;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 304 |
--- initial
+++ final
@@ -1,36 +1,30 @@
static int adis16260_probe(struct spi_device *spi) {
struct iio_dev *indio_dev;
struct adis *adis;
int ret;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*adis));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*adis));
+ if (indio_dev == NULL) return -ENOMEM;
adis = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16260_info;
indio_dev->channels = adis16260_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16260_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(adis, indio_dev, spi, &adis16260_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(adis, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis_initial_startup(adis);
if (ret) goto error_cleanup_buffer_trigger;
ret = iio_device_register(indio_dev);
if (ret) goto error_cleanup_buffer_trigger;
return 0;
error_cleanup_buffer_trigger:
adis_cleanup_buffer_and_trigger(adis, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 305 |
--- initial
+++ final
@@ -1,34 +1,32 @@
static int adis16136_probe(struct spi_device *spi) {
const struct spi_device_id *id = spi_get_device_id(spi);
struct adis16136 *adis16136;
struct iio_dev *indio_dev;
int ret;
- indio_dev = iio_device_alloc(sizeof(*adis16136));
+ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adis16136));
if (indio_dev == NULL) return -ENOMEM;
spi_set_drvdata(spi, indio_dev);
adis16136 = iio_priv(indio_dev);
adis16136->chip_info = &adis16136_chip_info[id->driver_data];
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->channels = adis16136_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16136_channels);
indio_dev->info = &adis16136_info;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(&adis16136->adis, indio_dev, spi, &adis16136_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(&adis16136->adis, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis16136_initial_setup(indio_dev);
if (ret) goto error_cleanup_buffer;
ret = iio_device_register(indio_dev);
if (ret) goto error_stop_device;
adis16136_debugfs_init(indio_dev);
return 0;
error_stop_device:
adis16136_stop_device(indio_dev);
error_cleanup_buffer:
adis_cleanup_buffer_and_trigger(&adis16136->adis, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@
f(T x) {
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(&x->dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
}<|end_of_text|> | 306 |
--- initial
+++ final
@@ -1,31 +1,25 @@
static int adis16080_probe(struct spi_device *spi) {
const struct spi_device_id *id = spi_get_device_id(spi);
int ret;
struct adis16080_state *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
/* Allocate the comms buffers */
st->us = spi;
st->info = &adis16080_chip_info[id->driver_data];
indio_dev->name = spi->dev.driver->name;
indio_dev->channels = adis16080_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16080_channels);
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16080_info;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
return 0;
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 307 |
--- initial
+++ final
@@ -1,36 +1,34 @@
static int ad5755_probe(struct spi_device *spi) {
enum ad5755_type type = spi_get_device_id(spi)->driver_data;
const struct ad5755_platform_data *pdata = dev_get_platdata(&spi->dev);
struct iio_dev *indio_dev;
struct ad5755_state *st;
int ret;
- indio_dev = iio_device_alloc(sizeof(*st));
+ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (indio_dev == NULL) {
dev_err(&spi->dev, "Failed to allocate iio device\n");
return -ENOMEM;
}
st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
st->chip_info = &ad5755_chip_info_tbl[type];
st->spi = spi;
st->pwr_down = 0xf;
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->info = &ad5755_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->num_channels = AD5755_NUM_CHANNELS;
if (!pdata) pdata = &ad5755_default_pdata;
ret = ad5755_init_channels(indio_dev, pdata);
- if (ret) goto error_free;
+ if (ret) return ret;
ret = ad5755_setup_pdata(indio_dev, pdata);
- if (ret) goto error_free;
+ if (ret) return ret;
ret = iio_device_register(indio_dev);
if (ret) {
dev_err(&spi->dev, "Failed to register iio device: %d\n", ret);
- goto error_free;
+ return ret;
}
return 0;
-error_free:
- iio_device_free(indio_dev);
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,x,f;
type T;
@@
f(T x) {
...
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(&x->dev, e1);
if (e == NULL) {
...
return e2;
}
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
return ret;
)
}<|end_of_text|> | 308 |
--- initial
+++ final
@@ -1,53 +1,47 @@
static int sca3000_probe(struct spi_device *spi) {
int ret;
struct sca3000_state *st;
struct iio_dev *indio_dev;
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);
st->us = spi;
mutex_init(&st->lock);
st->info = &sca3000_spi_chip_info_tbl[spi_get_device_id(spi)->driver_data];
indio_dev->dev.parent = &spi->dev;
indio_dev->name = spi_get_device_id(spi)->name;
if (st->info->temp_output)
indio_dev->info = &sca3000_info_with_temp;
else {
indio_dev->info = &sca3000_info;
indio_dev->channels = sca3000_channels;
indio_dev->num_channels = ARRAY_SIZE(sca3000_channels);
}
indio_dev->modes = INDIO_DIRECT_MODE;
sca3000_configure_ring(indio_dev);
ret = iio_device_register(indio_dev);
- if (ret < 0) goto error_free_dev;
+ if (ret < 0) return ret;
ret = iio_buffer_register(indio_dev, sca3000_channels, ARRAY_SIZE(sca3000_channels));
if (ret < 0) goto error_unregister_dev;
if (indio_dev->buffer) {
iio_scan_mask_set(indio_dev, indio_dev->buffer, 0);
iio_scan_mask_set(indio_dev, indio_dev->buffer, 1);
iio_scan_mask_set(indio_dev, indio_dev->buffer, 2);
}
if (spi->irq) {
ret = request_threaded_irq(spi->irq, NULL, &sca3000_event_handler, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "sca3000", indio_dev);
if (ret) goto error_unregister_ring;
}
sca3000_register_ring_funcs(indio_dev);
ret = sca3000_clean_setup(st);
if (ret) goto error_free_irq;
return 0;
error_free_irq:
if (spi->irq) free_irq(spi->irq, indio_dev);
error_unregister_ring:
iio_buffer_unregister(indio_dev);
error_unregister_dev:
iio_device_unregister(indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 309 |
--- initial
+++ final
@@ -1,46 +1,40 @@
static int adis16220_probe(struct spi_device *spi) {
int ret;
struct adis16220_state *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16220_info;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = adis16220_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16220_channels);
ret = iio_device_register(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &accel_bin);
if (ret) goto error_unregister_dev;
ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &adc1_bin);
if (ret) goto error_rm_accel_bin;
ret = sysfs_create_bin_file(&indio_dev->dev.kobj, &adc2_bin);
if (ret) goto error_rm_adc1_bin;
ret = adis_init(&st->adis, indio_dev, spi, &adis16220_data);
if (ret) goto error_rm_adc2_bin;
/* Get the device into a sane initial state */
ret = adis_initial_startup(&st->adis);
if (ret) goto error_rm_adc2_bin;
return 0;
error_rm_adc2_bin:
sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc2_bin);
error_rm_adc1_bin:
sysfs_remove_bin_file(&indio_dev->dev.kobj, &adc1_bin);
error_rm_accel_bin:
sysfs_remove_bin_file(&indio_dev->dev.kobj, &accel_bin);
error_unregister_dev:
iio_device_unregister(indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 310 |
--- initial
+++ final
@@ -1,53 +1,47 @@
static int lis3l02dq_probe(struct spi_device *spi) {
int ret;
struct lis3l02dq_state *st;
struct iio_dev *indio_dev;
- indio_dev = iio_device_alloc(sizeof *st);
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof *st);
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
st->us = spi;
st->gpio = of_get_gpio(spi->dev.of_node, 0);
mutex_init(&st->buf_lock);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &lis3l02dq_info;
indio_dev->channels = lis3l02dq_channels;
indio_dev->num_channels = ARRAY_SIZE(lis3l02dq_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
ret = lis3l02dq_configure_buffer(indio_dev);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = iio_buffer_register(indio_dev, lis3l02dq_channels, ARRAY_SIZE(lis3l02dq_channels));
if (ret) {
printk(KERN_ERR "failed to initialize the buffer\n");
goto error_unreg_buffer_funcs;
}
if (spi->irq) {
ret = request_threaded_irq(st->us->irq, &lis3l02dq_th, &lis3l02dq_event_handler, IRQF_TRIGGER_RISING, "lis3l02dq", indio_dev);
if (ret) goto error_uninitialize_buffer;
ret = lis3l02dq_probe_trigger(indio_dev);
if (ret) goto error_free_interrupt;
}
/* Get the device into a sane initial state */
ret = lis3l02dq_initial_setup(indio_dev);
if (ret) goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret) goto error_remove_trigger;
return 0;
error_remove_trigger:
if (spi->irq) lis3l02dq_remove_trigger(indio_dev);
error_free_interrupt:
if (spi->irq) free_irq(st->us->irq, indio_dev);
error_uninitialize_buffer:
iio_buffer_unregister(indio_dev);
error_unreg_buffer_funcs:
lis3l02dq_unconfigure_buffer(indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 311 |
--- initial
+++ final
@@ -1,36 +1,30 @@
static int adis16203_probe(struct spi_device *spi) {
int ret;
struct iio_dev *indio_dev;
struct adis *st;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->channels = adis16203_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16203_channels);
indio_dev->info = &adis16203_info;
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(st, indio_dev, spi, &adis16203_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis_initial_startup(st);
if (ret) goto error_cleanup_buffer_trigger;
ret = iio_device_register(indio_dev);
if (ret) goto error_cleanup_buffer_trigger;
return 0;
error_cleanup_buffer_trigger:
adis_cleanup_buffer_and_trigger(st, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 312 |
--- initial
+++ final
@@ -1,36 +1,30 @@
static int adis16209_probe(struct spi_device *spi) {
int ret;
struct adis *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16209_info;
indio_dev->channels = adis16209_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16209_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(st, indio_dev, spi, &adis16209_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis_initial_startup(st);
if (ret) goto error_cleanup_buffer_trigger;
ret = iio_device_register(indio_dev);
if (ret) goto error_cleanup_buffer_trigger;
return 0;
error_cleanup_buffer_trigger:
adis_cleanup_buffer_and_trigger(st, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 313 |
--- initial
+++ final
@@ -1,36 +1,30 @@
static int adis16204_probe(struct spi_device *spi) {
int ret;
struct adis *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16204_info;
indio_dev->channels = adis16204_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16204_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(st, indio_dev, spi, &adis16204_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis_initial_startup(st);
if (ret) goto error_cleanup_buffer_trigger;
ret = iio_device_register(indio_dev);
if (ret) goto error_cleanup_buffer_trigger;
return 0;
error_cleanup_buffer_trigger:
adis_cleanup_buffer_and_trigger(st, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 314 |
--- initial
+++ final
@@ -1,36 +1,30 @@
static int adis16240_probe(struct spi_device *spi) {
int ret;
struct adis *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16240_info;
indio_dev->channels = adis16240_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16240_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(st, indio_dev, spi, &adis16240_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis_initial_startup(st);
if (ret) goto error_cleanup_buffer_trigger;
ret = iio_device_register(indio_dev);
if (ret) goto error_cleanup_buffer_trigger;
return 0;
error_cleanup_buffer_trigger:
adis_cleanup_buffer_and_trigger(st, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 315 |
--- initial
+++ final
@@ -1,36 +1,30 @@
static int adis16201_probe(struct spi_device *spi) {
int ret;
struct adis *st;
struct iio_dev *indio_dev;
/* setup the industrialio driver allocated elements */
- indio_dev = iio_device_alloc(sizeof(*st));
- if (indio_dev == NULL) {
- ret = -ENOMEM;
- goto error_ret;
- }
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
+ if (indio_dev == NULL) return -ENOMEM;
st = iio_priv(indio_dev);
/* this is only used for removal purposes */
spi_set_drvdata(spi, indio_dev);
indio_dev->name = spi->dev.driver->name;
indio_dev->dev.parent = &spi->dev;
indio_dev->info = &adis16201_info;
indio_dev->channels = adis16201_channels;
indio_dev->num_channels = ARRAY_SIZE(adis16201_channels);
indio_dev->modes = INDIO_DIRECT_MODE;
ret = adis_init(st, indio_dev, spi, &adis16201_data);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL);
- if (ret) goto error_free_dev;
+ if (ret) return ret;
/* Get the device into a sane initial state */
ret = adis_initial_startup(st);
if (ret) goto error_cleanup_buffer_trigger;
ret = iio_device_register(indio_dev);
if (ret < 0) goto error_cleanup_buffer_trigger;
return 0;
error_cleanup_buffer_trigger:
adis_cleanup_buffer_and_trigger(st, indio_dev);
-error_free_dev:
- iio_device_free(indio_dev);
-error_ret:
return ret;
}<sep>@@
expression e,e1,e2,ret;
identifier l1,l2,x,f;
type T;
@@
f(T x) {
... when != l2
(
- e = iio_device_alloc(e1);
+ e = devm_iio_device_alloc(dev, e1);
if (e == NULL)
(
- {
- ret = e2;
- goto l2;
+ return e2;
- }
|
{
...
- ret = e2;
...
- goto l2;
+ return e2;
}
)
<...
- goto l1;
+ return ret;
...>
&
e = iio_device_alloc(e1);
... when exists
-l1:
- iio_device_free(e);
-l2:
return ret;
)
}
<|end_of_text|> | 316 |
--- initial
+++ final
@@ -1,47 +1,45 @@
int au0828_dvb_register(struct au0828_dev *dev) {
struct au0828_dvb *dvb = &dev->dvb;
int ret;
dprintk(1, "%s()\n", __func__);
/* init frontend */
switch (dev->boardnr) {
case AU0828_BOARD_HAUPPAUGE_HVR850:
case AU0828_BOARD_HAUPPAUGE_HVR950Q:
dvb->frontend = dvb_attach(au8522_attach, &hauppauge_hvr950q_config, &dev->i2c_adap);
if (dvb->frontend != NULL) switch (dev->board.tuner_type) {
default:
case TUNER_XC5000: dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap, &hauppauge_xc5000a_config); break;
case TUNER_XC5000C: dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap, &hauppauge_xc5000c_config); break;
}
break;
case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
dvb->frontend = dvb_attach(au8522_attach, &hauppauge_hvr950q_config, &dev->i2c_adap);
if (dvb->frontend != NULL) dvb_attach(mxl5007t_attach, dvb->frontend, &dev->i2c_adap, 0x60, &mxl5007t_hvr950q_config);
break;
case AU0828_BOARD_HAUPPAUGE_WOODBURY:
dvb->frontend = dvb_attach(au8522_attach, &hauppauge_woodbury_config, &dev->i2c_adap);
if (dvb->frontend != NULL) dvb_attach(tda18271_attach, dvb->frontend, 0x60, &dev->i2c_adap, &hauppauge_woodbury_tunerconfig);
break;
case AU0828_BOARD_DVICO_FUSIONHDTV7:
dvb->frontend = dvb_attach(au8522_attach, &fusionhdtv7usb_config, &dev->i2c_adap);
if (dvb->frontend != NULL) { dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap, &hauppauge_xc5000a_config); }
break;
default: pr_warn("The frontend of your DVB/ATSC card isn't supported yet\n"); break;
}
if (NULL == dvb->frontend) {
pr_err("%s() Frontend initialization failed\n", __func__);
return -1;
}
/* define general-purpose callback pointer */
dvb->frontend->callback = au0828_tuner_callback;
/* register everything */
ret = dvb_register(dev);
if (ret < 0) {
if (dvb->frontend->ops.release) dvb->frontend->ops.release(dvb->frontend);
dvb->frontend = NULL;
return ret;
}
- dev->bulk_timeout.function = au0828_bulk_timeout;
- dev->bulk_timeout.data = (unsigned long)dev;
- init_timer(&dev->bulk_timeout);
+ setup_timer(&dev->bulk_timeout, au0828_bulk_timeout, (unsigned long)dev);
return 0;
}<sep>@@
expression t,d,f,e1,e2,e3;
@@
- t.function = f;
... when != f = e3
- t.data = d;
... when != d = e1
when != f = e2
- init_timer(&t);
+ setup_timer(&t,f,d);
<|end_of_text|> | 320 |
--- initial
+++ final
@@ -1,8 +1,7 @@
static inline void clocksource_start_watchdog(void) {
if (watchdog_running || !watchdog || list_empty(&watchdog_list)) return;
- init_timer(&watchdog_timer);
- watchdog_timer.function = clocksource_watchdog;
+ setup_timer(&watchdog_timer, clocksource_watchdog, 0UL);
watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL;
add_timer_on(&watchdog_timer, cpumask_first(cpu_online_mask));
watchdog_running = 1;
}<sep>@@
expression t,d,f,e3;
@@
- init_timer(&t);
+ setup_timer(&t,f,0UL);
... when != f = e3
- t.function = f;
<|end_of_text|> | 322 |
--- initial
+++ final
@@ -1,9 +1,7 @@
void fsm_settimer(fsm_instance *fi, fsm_timer *this) {
this->fi = fi;
- this->tl.function = (void *)fsm_expire_timer;
- this->tl.data = (long)this;
#if FSM_TIMER_DEBUG
printk(KERN_DEBUG "fsm(%s): Create timer %p\n", fi->name, this);
#endif
- init_timer(&this->tl);
+ setup_timer(&this->tl, (void *)fsm_expire_timer, (long)this);
}<sep>@@
expression t,d,f,e1,e2,e3;
@@
- t.function = f;
... when != f = e3
- t.data = d;
... when != d = e1
when != f = e2
- init_timer(&t);
+ setup_timer(&t,f,d);
<|end_of_text|> | 330 |
--- initial
+++ final
@@ -1,61 +1,60 @@
static int __init isdn_init(void) {
int i;
char tmprev[50];
dev = vzalloc(sizeof(isdn_dev));
if (!dev) {
printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
return -EIO;
}
- init_timer(&dev->timer);
- dev->timer.function = isdn_timer_funct;
+ setup_timer(&dev->timer, isdn_timer_funct, 0UL);
spin_lock_init(&dev->lock);
spin_lock_init(&dev->timerlock);
#ifdef MODULE
dev->owner = THIS_MODULE;
#endif
mutex_init(&dev->mtx);
init_waitqueue_head(&dev->info_waitq);
for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
dev->drvmap[i] = -1;
dev->chanmap[i] = -1;
dev->m_idx[i] = -1;
strcpy(dev->num[i], "???");
}
if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
printk(KERN_WARNING "isdn: Could not register control devices\n");
vfree(dev);
return -EIO;
}
if ((isdn_tty_modem_init()) < 0) {
printk(KERN_WARNING "isdn: Could not register tty devices\n");
vfree(dev);
unregister_chrdev(ISDN_MAJOR, "isdn");
return -EIO;
}
#ifdef CONFIG_ISDN_PPP
if (isdn_ppp_init() < 0) {
printk(KERN_WARNING "isdn: Could not create PPP-device-structs\n");
isdn_tty_exit();
unregister_chrdev(ISDN_MAJOR, "isdn");
vfree(dev);
return -EIO;
}
#endif /* CONFIG_ISDN_PPP */
strcpy(tmprev, isdn_revision);
printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
strcpy(tmprev, isdn_net_revision);
printk("%s/", isdn_getrev(tmprev));
strcpy(tmprev, isdn_ppp_revision);
printk("%s/", isdn_getrev(tmprev));
strcpy(tmprev, isdn_audio_revision);
printk("%s/", isdn_getrev(tmprev));
strcpy(tmprev, isdn_v110_revision);
printk("%s", isdn_getrev(tmprev));
#ifdef MODULE
printk(" loaded\n");
#else
printk("\n");
#endif
isdn_info_update();
return 0;
}<sep>@@
expression t,d,f,e3;
@@
- init_timer(&t);
+ setup_timer(&t,f,0UL);
... when != f = e3
- t.function = f;
<|end_of_text|> | 333 |
--- initial
+++ final
@@ -1,19 +1,18 @@
static int __init n2100_request_gpios(void) {
int ret;
if (!machine_is_n2100()) return 0;
ret = gpio_request(N2100_HARDWARE_RESET, "reset");
if (ret) pr_err("could not request reset GPIO\n");
ret = gpio_request(N2100_POWER_BUTTON, "power");
if (ret)
pr_err("could not request power GPIO\n");
else {
ret = gpio_direction_input(N2100_POWER_BUTTON);
if (ret) pr_err("could not set power GPIO as input\n");
}
/* Set up power button poll timer */
- init_timer(&power_button_poll_timer);
- power_button_poll_timer.function = power_button_poll;
+ setup_timer(&power_button_poll_timer, power_button_poll, 0UL);
power_button_poll_timer.expires = jiffies + (HZ / 10);
add_timer(&power_button_poll_timer);
return 0;
}<sep>@@
expression t,d,f,e3;
@@
- init_timer(&t);
+ setup_timer(&t,f,0UL);
... when != f = e3
- t.function = f;
<|end_of_text|> | 337 |
--- initial
+++ final
@@ -1,11 +1,10 @@
static int __init init_nmi_wdt(void) {
nmi_wdt_set_timeout(timeout);
nmi_wdt_start();
nmi_active = true;
- init_timer(&ntimer);
- ntimer.function = nmi_wdt_timer;
+ setup_timer(&ntimer, nmi_wdt_timer, 0UL);
ntimer.expires = jiffies + NMI_CHECK_TIMEOUT;
add_timer(&ntimer);
pr_info("nmi_wdt: initialized: timeout=%d sec\n", timeout);
return 0;
}<sep>@@
expression t,d,f,e3;
@@
- init_timer(&t);
+ setup_timer(&t,f,0UL);
... when != f = e3
- t.function = f;
<|end_of_text|> | 341 |
--- initial
+++ final
@@ -1,6 +1,5 @@
static void init_battery_timer(void) {
- init_timer(&battery_timer);
- battery_timer.function = check_all_batteries;
+ setup_timer(&battery_timer, check_all_batteries, 0UL);
battery_timer.expires = jiffies + (HZ * 60);
add_timer(&battery_timer);
}<sep>@@
expression t,d,f,e3;
@@
- init_timer(&t);
+ setup_timer(&t,f,0UL);
... when != f = e3
- t.function = f;
<|end_of_text|> | 349 |
--- initial
+++ final
@@ -1,6 +1 @@
-static void fq_free(void *addr) {
- if (addr && is_vmalloc_addr(addr))
- vfree(addr);
- else
- kfree(addr);
-}
+static void fq_free(void *addr) { kvfree(addr); }<sep>@@
expression e;
@@
- if (e != NULL && is_vmalloc_addr(e))
- vfree(e);
- else
- kfree(e);
+ kvfree(e);
<|end_of_text|> | 474 |
--- initial
+++ final
@@ -1,29 +1,26 @@
static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order) {
int i, s;
buddy->max_order = max_order;
spin_lock_init(&buddy->lock);
buddy->bits = kcalloc(buddy->max_order + 1, sizeof(long *), GFP_KERNEL);
buddy->num_free = kcalloc((buddy->max_order + 1), sizeof *buddy->num_free, GFP_KERNEL);
if (!buddy->bits || !buddy->num_free) goto err_out;
for (i = 0; i <= buddy->max_order; ++i) {
s = BITS_TO_LONGS(1 << (buddy->max_order - i));
buddy->bits[i] = kcalloc(s, sizeof(long), GFP_KERNEL | __GFP_NOWARN);
if (!buddy->bits[i]) {
buddy->bits[i] = vzalloc(s * sizeof(long));
if (!buddy->bits[i]) goto err_out_free;
}
}
set_bit(0, buddy->bits[buddy->max_order]);
buddy->num_free[buddy->max_order] = 1;
return 0;
err_out_free:
for (i = 0; i <= buddy->max_order; ++i)
- if (buddy->bits[i] && is_vmalloc_addr(buddy->bits[i]))
- vfree(buddy->bits[i]);
- else
- kfree(buddy->bits[i]);
+ kvfree(buddy->bits[i]);
err_out:
kfree(buddy->bits);
kfree(buddy->num_free);
return -ENOMEM;
}<sep>@@
expression e;
@@
- if (e != NULL && is_vmalloc_addr(e))
- vfree(e);
- else
- kfree(e);
+ kvfree(e);
<|end_of_text|> | 482 |
--- initial
+++ final
@@ -1,15 +1,12 @@
void nvdimm_drvdata_release(struct kref *kref) {
struct nvdimm_drvdata *ndd = container_of(kref, typeof(*ndd), kref);
struct device *dev = ndd->dev;
struct resource *res, *_r;
dev_dbg(dev, "%s\n", __func__);
nvdimm_bus_lock(dev);
for_each_dpa_resource_safe(ndd, res, _r) nvdimm_free_dpa(ndd, res);
nvdimm_bus_unlock(dev);
- if (ndd->data && is_vmalloc_addr(ndd->data))
- vfree(ndd->data);
- else
- kfree(ndd->data);
+ kvfree(ndd->data);
kfree(ndd);
put_device(dev);
}<sep>@@
expression e;
@@
- if (e != NULL && is_vmalloc_addr(e))
- vfree(e);
- else
- kfree(e);
+ kvfree(e);
<|end_of_text|> | 500 |
--- initial
+++ final
@@ -1,7 +1,7 @@
static int __init fid_init(void) {
int rc;
rc = libcfs_setup();
if (rc) return rc;
- seq_debugfs_dir = ldebugfs_register(LUSTRE_SEQ_NAME, debugfs_lustre_root, NULL, NULL);
- return PTR_ERR_OR_ZERO(seq_debugfs_dir);
+ seq_debugfs_dir = debugfs_create_dir(LUSTRE_SEQ_NAME, debugfs_lustre_root);
+ return 0;
}<sep>@@
expression e,e1,e2,e3;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-return PTR_ERR_OR_ZERO(e);
+return 0;
<|end_of_text|> | 649 |
--- initial
+++ final
@@ -1,19 +1,13 @@
static int seq_client_debugfs_init(struct lu_client_seq *seq) {
int rc;
- seq->lcs_debugfs_entry = ldebugfs_register(seq->lcs_name, seq_debugfs_dir, NULL, NULL);
- if (IS_ERR_OR_NULL(seq->lcs_debugfs_entry)) {
- CERROR("%s: LdebugFS failed in seq-init\n", seq->lcs_name);
- rc = seq->lcs_debugfs_entry ? PTR_ERR(seq->lcs_debugfs_entry) : -ENOMEM;
- seq->lcs_debugfs_entry = NULL;
- return rc;
- }
+ seq->lcs_debugfs_entry = debugfs_create_dir(seq->lcs_name, seq_debugfs_dir);
rc = ldebugfs_add_vars(seq->lcs_debugfs_entry, seq_client_debugfs_list, seq);
if (rc) {
CERROR("%s: Can't init sequence manager debugfs, rc %d\n", seq->lcs_name, rc);
goto out_cleanup;
}
return 0;
out_cleanup:
seq_client_debugfs_fini(seq);
return rc;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR_OR_NULL(e)) S
<|end_of_text|> | 650 |
--- initial
+++ final
@@ -1,19 +1,13 @@
static int fld_client_debugfs_init(struct lu_client_fld *fld) {
int rc;
- fld->lcf_debugfs_entry = ldebugfs_register(fld->lcf_name, fld_debugfs_dir, NULL, NULL);
- if (IS_ERR_OR_NULL(fld->lcf_debugfs_entry)) {
- CERROR("%s: LdebugFS failed in fld-init\n", fld->lcf_name);
- rc = fld->lcf_debugfs_entry ? PTR_ERR(fld->lcf_debugfs_entry) : -ENOMEM;
- fld->lcf_debugfs_entry = NULL;
- return rc;
- }
+ fld->lcf_debugfs_entry = debugfs_create_dir(fld->lcf_name, fld_debugfs_dir);
rc = ldebugfs_add_vars(fld->lcf_debugfs_entry, fld_client_debugfs_list, fld);
if (rc) {
CERROR("%s: Can't init FLD debufs, rc %d\n", fld->lcf_name, rc);
goto out_cleanup;
}
return 0;
out_cleanup:
fld_client_debugfs_fini(fld);
return rc;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR_OR_NULL(e)) S
<|end_of_text|> | 651 |
--- initial
+++ final
@@ -1,7 +1,7 @@
static int __init fld_init(void) {
int rc;
rc = libcfs_setup();
if (rc) return rc;
- fld_debugfs_dir = ldebugfs_register(LUSTRE_FLD_NAME, debugfs_lustre_root, NULL, NULL);
- return PTR_ERR_OR_ZERO(fld_debugfs_dir);
+ fld_debugfs_dir = debugfs_create_dir(LUSTRE_FLD_NAME, debugfs_lustre_root);
+ return 0;
}<sep>@@
expression e,e1,e2,e3;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-return PTR_ERR_OR_ZERO(e);
+return 0;
<|end_of_text|> | 652 |
--- initial
+++ final
@@ -1,49 +1,44 @@
int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops, const char *name, struct lu_device_type *ldt) {
struct obd_type *type;
int rc;
/* sanity check */
LASSERT(strnlen(name, CLASS_MAX_NAME) < CLASS_MAX_NAME);
if (class_search_type(name)) {
CDEBUG(D_IOCTL, "Type %s already registered\n", name);
return -EEXIST;
}
rc = -ENOMEM;
type = kzalloc(sizeof(*type), GFP_NOFS);
if (!type) return rc;
type->typ_dt_ops = kzalloc(sizeof(*type->typ_dt_ops), GFP_NOFS);
type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS);
type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);
if (!type->typ_dt_ops || !type->typ_md_ops || !type->typ_name) goto failed;
*type->typ_dt_ops = *dt_ops;
/* md_ops is optional */
if (md_ops) *type->typ_md_ops = *md_ops;
strcpy(type->typ_name, name);
spin_lock_init(&type->obd_type_lock);
- type->typ_debugfs_entry = ldebugfs_register(type->typ_name, debugfs_lustre_root, NULL, type);
- if (IS_ERR_OR_NULL(type->typ_debugfs_entry)) {
- rc = type->typ_debugfs_entry ? PTR_ERR(type->typ_debugfs_entry) : -ENOMEM;
- type->typ_debugfs_entry = NULL;
- goto failed;
- }
+ type->typ_debugfs_entry = debugfs_create_dir(type->typ_name, debugfs_lustre_root);
type->typ_kobj = kobject_create_and_add(type->typ_name, lustre_kobj);
if (!type->typ_kobj) {
rc = -ENOMEM;
goto failed;
}
if (ldt) {
type->typ_lu = ldt;
rc = lu_device_type_init(ldt);
if (rc != 0) goto failed;
}
spin_lock(&obd_types_lock);
list_add(&type->typ_chain, &obd_types);
spin_unlock(&obd_types_lock);
return 0;
failed:
if (type->typ_kobj) kobject_put(type->typ_kobj);
kfree(type->typ_name);
kfree(type->typ_md_ops);
kfree(type->typ_dt_ops);
kfree(type);
return rc;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR_OR_NULL(e)) S
<|end_of_text|> | 653 |
--- initial
+++ final
@@ -1,46 +1,40 @@
static int ldlm_pool_debugfs_init(struct ldlm_pool *pl) {
struct ldlm_namespace *ns = container_of(pl, struct ldlm_namespace, ns_pool);
struct dentry *debugfs_ns_parent;
struct lprocfs_vars pool_vars[2];
char *var_name = NULL;
int rc = 0;
var_name = kzalloc(MAX_STRING_SIZE + 1, GFP_NOFS);
if (!var_name) return -ENOMEM;
debugfs_ns_parent = ns->ns_debugfs_entry;
if (IS_ERR_OR_NULL(debugfs_ns_parent)) {
CERROR("%s: debugfs entry is not initialized\n", ldlm_ns_name(ns));
rc = -EINVAL;
goto out_free_name;
}
- pl->pl_debugfs_entry = ldebugfs_register("pool", debugfs_ns_parent, NULL, NULL);
- if (IS_ERR(pl->pl_debugfs_entry)) {
- CERROR("LdebugFS failed in ldlm-pool-init\n");
- rc = PTR_ERR(pl->pl_debugfs_entry);
- pl->pl_debugfs_entry = NULL;
- goto out_free_name;
- }
+ pl->pl_debugfs_entry = debugfs_create_dir("pool", debugfs_ns_parent);
var_name[MAX_STRING_SIZE] = '\0';
memset(pool_vars, 0, sizeof(pool_vars));
pool_vars[0].name = var_name;
LDLM_POOL_ADD_VAR(state, pl, &lprocfs_pool_state_fops);
pl->pl_stats = lprocfs_alloc_stats(LDLM_POOL_LAST_STAT - LDLM_POOL_FIRST_STAT, 0);
if (!pl->pl_stats) {
rc = -ENOMEM;
goto out_free_name;
}
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANTED_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "granted", "locks");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANT_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "grant", "locks");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_CANCEL_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "cancel", "locks");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANT_RATE_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "grant_rate", "locks/s");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_CANCEL_RATE_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "cancel_rate", "locks/s");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANT_PLAN_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "grant_plan", "locks/s");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_SLV_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "slv", "slv");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_SHRINK_REQTD_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "shrink_request", "locks");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_SHRINK_FREED_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "shrink_freed", "locks");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_RECALC_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "recalc_freed", "locks");
lprocfs_counter_init(pl->pl_stats, LDLM_POOL_TIMING_STAT, LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV, "recalc_timing", "sec");
debugfs_create_file("stats", 0644, pl->pl_debugfs_entry, pl->pl_stats, &lprocfs_stats_seq_fops);
out_free_name:
kfree(var_name);
return rc;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR(e)) S
<|end_of_text|> | 654 |
--- initial
+++ final
@@ -1,38 +1,23 @@
int ldlm_debugfs_setup(void) {
int rc;
- ldlm_debugfs_dir = ldebugfs_register(OBD_LDLM_DEVICENAME, debugfs_lustre_root, NULL, NULL);
- if (IS_ERR_OR_NULL(ldlm_debugfs_dir)) {
- CERROR("LProcFS failed in ldlm-init\n");
- rc = ldlm_debugfs_dir ? PTR_ERR(ldlm_debugfs_dir) : -ENOMEM;
- goto err;
- }
- ldlm_ns_debugfs_dir = ldebugfs_register("namespaces", ldlm_debugfs_dir, NULL, NULL);
- if (IS_ERR_OR_NULL(ldlm_ns_debugfs_dir)) {
- CERROR("LProcFS failed in ldlm-init\n");
- rc = ldlm_ns_debugfs_dir ? PTR_ERR(ldlm_ns_debugfs_dir) : -ENOMEM;
- goto err_type;
- }
- ldlm_svc_debugfs_dir = ldebugfs_register("services", ldlm_debugfs_dir, NULL, NULL);
- if (IS_ERR_OR_NULL(ldlm_svc_debugfs_dir)) {
- CERROR("LProcFS failed in ldlm-init\n");
- rc = ldlm_svc_debugfs_dir ? PTR_ERR(ldlm_svc_debugfs_dir) : -ENOMEM;
- goto err_ns;
- }
+ ldlm_debugfs_dir = debugfs_create_dir(OBD_LDLM_DEVICENAME, debugfs_lustre_root);
+ ldlm_ns_debugfs_dir = debugfs_create_dir("namespaces", ldlm_debugfs_dir);
+ ldlm_svc_debugfs_dir = debugfs_create_dir("services", ldlm_debugfs_dir);
rc = ldebugfs_add_vars(ldlm_debugfs_dir, ldlm_debugfs_list, NULL);
if (rc) {
CERROR("LProcFS failed in ldlm-init\n");
goto err_svc;
}
return 0;
err_svc:
ldebugfs_remove(&ldlm_svc_debugfs_dir);
err_ns:
ldebugfs_remove(&ldlm_ns_debugfs_dir);
err_type:
ldebugfs_remove(&ldlm_debugfs_dir);
err:
ldlm_svc_debugfs_dir = NULL;
ldlm_ns_debugfs_dir = NULL;
ldlm_debugfs_dir = NULL;
return rc;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR_OR_NULL(e)) S
<|end_of_text|> | 655 |
--- initial
+++ final
@@ -1,45 +1,45 @@
int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg) {
struct lprocfs_static_vars lvars = {NULL};
struct lov_desc *desc;
struct lov_obd *lov = &obd->u.lov;
int rc;
if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
CERROR("LOV setup requires a descriptor\n");
return -EINVAL;
}
desc = (struct lov_desc *)lustre_cfg_buf(lcfg, 1);
if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
CERROR("descriptor size wrong: %d > %d\n", (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
return -EINVAL;
}
if (desc->ld_magic != LOV_DESC_MAGIC) {
if (desc->ld_magic == __swab32(LOV_DESC_MAGIC)) {
CDEBUG(D_OTHER, "%s: Swabbing lov desc %p\n", obd->obd_name, desc);
lustre_swab_lov_desc(desc);
} else {
CERROR("%s: Bad lov desc magic: %#x\n", obd->obd_name, desc->ld_magic);
return -EINVAL;
}
}
lov_fix_desc(desc);
desc->ld_active_tgt_count = 0;
lov->desc = *desc;
lov->lov_tgt_size = 0;
mutex_init(&lov->lov_lock);
atomic_set(&lov->lov_refcount, 0);
lov->lov_sp_me = LUSTRE_SP_CLI;
init_rwsem(&lov->lov_notify_lock);
INIT_LIST_HEAD(&lov->lov_pool_list);
lov->lov_pool_count = 0;
rc = lov_pool_hash_init(&lov->lov_pools_hash_body);
if (rc) goto out;
rc = lov_ost_pool_init(&lov->lov_packed, 0);
if (rc) goto out;
lprocfs_lov_init_vars(&lvars);
lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
debugfs_create_file("target_obd", 0444, obd->obd_debugfs_entry, obd, &lov_proc_target_fops);
- lov->lov_pool_debugfs_entry = ldebugfs_register("pools", obd->obd_debugfs_entry, NULL, NULL);
+ lov->lov_pool_debugfs_entry = debugfs_create_dir("pools", obd->obd_debugfs_entry);
return 0;
out:
return rc;
}<sep>@@
expression e1,e2,e3;
@@
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
<|end_of_text|> | 656 |
--- initial
+++ final
@@ -1,76 +1,71 @@
int ldebugfs_register_mountpoint(struct dentry *parent, struct super_block *sb, char *osc, char *mdc) {
struct lustre_sb_info *lsi = s2lsi(sb);
struct ll_sb_info *sbi = ll_s2sbi(sb);
struct obd_device *obd;
struct dentry *dir;
char name[MAX_STRING_SIZE + 1], *ptr;
int err, id, len;
name[MAX_STRING_SIZE] = '\0';
LASSERT(sbi);
LASSERT(mdc);
LASSERT(osc);
/* Get fsname */
len = strlen(lsi->lsi_lmd->lmd_profile);
ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
if (ptr && (strcmp(ptr, "-client") == 0)) len -= 7;
/* Mount info */
snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len, lsi->lsi_lmd->lmd_profile, sb);
- dir = ldebugfs_register(name, parent, NULL, NULL);
- if (IS_ERR_OR_NULL(dir)) {
- err = dir ? PTR_ERR(dir) : -ENOMEM;
- sbi->ll_debugfs_entry = NULL;
- return err;
- }
+ dir = debugfs_create_dir(name, parent);
sbi->ll_debugfs_entry = dir;
debugfs_create_file("dump_page_cache", 0444, dir, sbi, &vvp_dump_pgcache_file_ops);
debugfs_create_file("extents_stats", 0644, dir, sbi, &ll_rw_extents_stats_fops);
debugfs_create_file("extents_stats_per_process", 0644, dir, sbi, &ll_rw_extents_stats_pp_fops);
debugfs_create_file("offset_stats", 0644, dir, sbi, &ll_rw_offset_stats_fops);
/* File operations stats */
sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES, LPROCFS_STATS_FLAG_NONE);
if (!sbi->ll_stats) {
err = -ENOMEM;
goto out;
}
/* do counter init */
for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
__u32 type = llite_opcode_table[id].type;
void *ptr = NULL;
if (type & LPROCFS_TYPE_REGS)
ptr = "regs";
else if (type & LPROCFS_TYPE_BYTES)
ptr = "bytes";
else if (type & LPROCFS_TYPE_PAGES)
ptr = "pages";
lprocfs_counter_init(sbi->ll_stats, llite_opcode_table[id].opcode, (type & LPROCFS_CNTR_AVGMINMAX), llite_opcode_table[id].opname, ptr);
}
debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry, sbi->ll_stats, &lprocfs_stats_seq_fops);
sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string), LPROCFS_STATS_FLAG_NONE);
if (!sbi->ll_ra_stats) {
err = -ENOMEM;
goto out;
}
for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
lprocfs_counter_init(sbi->ll_ra_stats, id, 0, ra_stat_string[id], "pages");
debugfs_create_file("stats", 0644, sbi->ll_debugfs_entry, sbi->ll_ra_stats, &lprocfs_stats_seq_fops);
err = ldebugfs_add_vars(sbi->ll_debugfs_entry, lprocfs_llite_obd_vars, sb);
if (err) goto out;
sbi->ll_kobj.kset = llite_kset;
init_completion(&sbi->ll_kobj_unregister);
err = kobject_init_and_add(&sbi->ll_kobj, &llite_ktype, NULL, "%s", name);
if (err) goto out;
/* MDC info */
obd = class_name2obd(mdc);
err = sysfs_create_link(&sbi->ll_kobj, &obd->obd_kobj, obd->obd_type->typ_name);
if (err) goto out;
/* OSC */
obd = class_name2obd(osc);
err = sysfs_create_link(&sbi->ll_kobj, &obd->obd_kobj, obd->obd_type->typ_name);
out:
if (err) {
ldebugfs_remove(&sbi->ll_debugfs_entry);
lprocfs_free_stats(&sbi->ll_ra_stats);
lprocfs_free_stats(&sbi->ll_stats);
}
return err;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR_OR_NULL(e)) S
<|end_of_text|> | 657 |
--- initial
+++ final
@@ -1,40 +1,35 @@
static void ptlrpc_ldebugfs_register(struct dentry *root, char *dir, char *name, struct dentry **debugfs_root_ret, struct lprocfs_stats **stats_ret) {
struct dentry *svc_debugfs_entry;
struct lprocfs_stats *svc_stats;
int i;
unsigned int svc_counter_config = LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV;
LASSERT(!*debugfs_root_ret);
LASSERT(!*stats_ret);
svc_stats = lprocfs_alloc_stats(EXTRA_MAX_OPCODES + LUSTRE_MAX_OPCODES, 0);
if (!svc_stats) return;
- if (dir) {
- svc_debugfs_entry = ldebugfs_register(dir, root, NULL, NULL);
- if (IS_ERR(svc_debugfs_entry)) {
- lprocfs_free_stats(&svc_stats);
- return;
- }
- } else {
+ if (dir)
+ svc_debugfs_entry = debugfs_create_dir(dir, root);
+ else
svc_debugfs_entry = root;
- }
lprocfs_counter_init(svc_stats, PTLRPC_REQWAIT_CNTR, svc_counter_config, "req_waittime", "usec");
lprocfs_counter_init(svc_stats, PTLRPC_REQQDEPTH_CNTR, svc_counter_config, "req_qdepth", "reqs");
lprocfs_counter_init(svc_stats, PTLRPC_REQACTIVE_CNTR, svc_counter_config, "req_active", "reqs");
lprocfs_counter_init(svc_stats, PTLRPC_TIMEOUT, svc_counter_config, "req_timeout", "sec");
lprocfs_counter_init(svc_stats, PTLRPC_REQBUF_AVAIL_CNTR, svc_counter_config, "reqbuf_avail", "bufs");
for (i = 0; i < EXTRA_LAST_OPC; i++) {
char *units;
switch (i) {
case BRW_WRITE_BYTES:
case BRW_READ_BYTES: units = "bytes"; break;
default: units = "reqs"; break;
}
lprocfs_counter_init(svc_stats, PTLRPC_LAST_CNTR + i, svc_counter_config, ll_eopcode2str(i), units);
}
for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
__u32 opcode = ll_rpc_opcode_table[i].opcode;
lprocfs_counter_init(svc_stats, EXTRA_MAX_OPCODES + i, svc_counter_config, ll_opcode2str(opcode), "usec");
}
debugfs_create_file("stats", 0644, svc_debugfs_entry, svc_stats, &lprocfs_stats_seq_fops);
if (dir) *debugfs_root_ret = svc_debugfs_entry;
*stats_ret = svc_stats;
}<sep>@@
expression e,e1,e2,e3;
statement S;
@@
e =
- ldebugfs_register
+ debugfs_create_dir
(e1,e2
- ,NULL,e3
)
;
-if (IS_ERR(e)) S
@@
expression e,e1,e2;
statement S;
@@
if (...)
- {
e = debugfs_create_dir(e1,e2);
- }
else
- {
S
- }
<|end_of_text|> | 658 |
--- initial
+++ final
@@ -1,36 +1,35 @@
static int set_register(pegasus_t *pegasus, __u16 indx, __u8 data) {
int ret;
char *tmp;
DECLARE_WAITQUEUE(wait, current);
- tmp = kmalloc(1, GFP_KERNEL);
+ tmp = kmemdup(&data, 1, GFP_KERNEL);
if (!tmp) {
netif_warn(pegasus, drv, pegasus->net, "out of memory in %s\n", __func__);
return -ENOMEM;
}
- memcpy(tmp, &data, 1);
add_wait_queue(&pegasus->ctrl_wait, &wait);
set_current_state(TASK_UNINTERRUPTIBLE);
while (pegasus->flags & ETH_REGS_CHANGED)
schedule();
remove_wait_queue(&pegasus->ctrl_wait, &wait);
set_current_state(TASK_RUNNING);
pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
pegasus->dr.bRequest = PEGASUS_REQ_SET_REG;
pegasus->dr.wValue = cpu_to_le16(data);
pegasus->dr.wIndex = cpu_to_le16(indx);
pegasus->dr.wLength = cpu_to_le16(1);
pegasus->ctrl_urb->transfer_buffer_length = 1;
usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), (char *)&pegasus->dr, tmp, 1, ctrl_callback, pegasus);
add_wait_queue(&pegasus->ctrl_wait, &wait);
set_current_state(TASK_UNINTERRUPTIBLE);
if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
if (ret == -ENODEV) netif_device_detach(pegasus->net);
if (net_ratelimit()) netif_err(pegasus, drv, pegasus->net, "%s, status %d\n", __func__, ret);
goto out;
}
schedule();
out:
remove_wait_queue(&pegasus->ctrl_wait, &wait);
kfree(tmp);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 659 |
--- initial
+++ final
@@ -1,36 +1,35 @@
static int set_registers(pegasus_t *pegasus, __u16 indx, __u16 size, void *data) {
int ret;
char *buffer;
DECLARE_WAITQUEUE(wait, current);
- buffer = kmalloc(size, GFP_KERNEL);
+ buffer = kmemdup(data, size, GFP_KERNEL);
if (!buffer) {
netif_warn(pegasus, drv, pegasus->net, "out of memory in %s\n", __func__);
return -ENOMEM;
}
- memcpy(buffer, data, size);
add_wait_queue(&pegasus->ctrl_wait, &wait);
set_current_state(TASK_UNINTERRUPTIBLE);
while (pegasus->flags & ETH_REGS_CHANGED)
schedule();
remove_wait_queue(&pegasus->ctrl_wait, &wait);
set_current_state(TASK_RUNNING);
pegasus->dr.bRequestType = PEGASUS_REQT_WRITE;
pegasus->dr.bRequest = PEGASUS_REQ_SET_REGS;
pegasus->dr.wValue = cpu_to_le16(0);
pegasus->dr.wIndex = cpu_to_le16(indx);
pegasus->dr.wLength = cpu_to_le16(size);
pegasus->ctrl_urb->transfer_buffer_length = size;
usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb, usb_sndctrlpipe(pegasus->usb, 0), (char *)&pegasus->dr, buffer, size, ctrl_callback, pegasus);
add_wait_queue(&pegasus->ctrl_wait, &wait);
set_current_state(TASK_UNINTERRUPTIBLE);
if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
if (ret == -ENODEV) netif_device_detach(pegasus->net);
netif_err(pegasus, drv, pegasus->net, "%s, status %d\n", __func__, ret);
goto out;
}
schedule();
out:
remove_wait_queue(&pegasus->ctrl_wait, &wait);
kfree(buffer);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 660 |
--- initial
+++ final
@@ -1,14 +1,13 @@
static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 size, void *data) {
void *buf = NULL;
int err = -ENOMEM;
netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n", cmd, value, index, size);
if (data) {
- buf = kmalloc(size, GFP_KERNEL);
+ buf = kmemdup(data, size, GFP_KERNEL);
if (!buf) goto out;
- memcpy(buf, data, size);
}
err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), cmd, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, value, index, buf, size, USB_CTRL_SET_TIMEOUT);
kfree(buf);
out:
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 661 |
--- initial
+++ final
@@ -1,11 +1,10 @@
static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data) {
struct usb_device *xdev = dev->udev;
int ret;
void *buffer;
- buffer = kmalloc(size, GFP_NOIO);
+ buffer = kmemdup(data, size, GFP_NOIO);
if (buffer == NULL) return -ENOMEM;
- memcpy(buffer, data, size);
ret = usb_control_msg(xdev, usb_sndctrlpipe(xdev, 0), MCS7830_WR_BREQ, MCS7830_WR_BMREQ, 0x0000, index, buffer, size, MCS7830_CTRL_TIMEOUT);
kfree(buffer);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 662 |
--- initial
+++ final
@@ -1,15 +1,14 @@
static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data) {
void *buf = NULL;
int err = -ENOMEM;
netdev_dbg(dev->net, "dm_write() reg=0x%02x, length=%d\n", reg, length);
if (data) {
- buf = kmalloc(length, GFP_KERNEL);
+ buf = kmemdup(data, length, GFP_KERNEL);
if (!buf) goto out;
- memcpy(buf, data, length);
}
err = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), DM_WRITE_REGS, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, reg, buf, length, USB_CTRL_SET_TIMEOUT);
kfree(buf);
if (err >= 0 && err < length) err = -EINVAL;
out:
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 663 |
--- initial
+++ final
@@ -1,77 +1,76 @@
static void if_usb_receive_fwload(struct urb *urb) {
struct if_usb_card *cardp = urb->context;
struct sk_buff *skb = cardp->rx_skb;
struct fwsyncheader *syncfwheader;
struct bootcmdresp bootcmdresp;
if (urb->status) {
lbs_deb_usbd(&cardp->udev->dev, "URB status is failed during fw load\n");
kfree_skb(skb);
return;
}
if (cardp->fwdnldover) {
__le32 *tmp = (__le32 *)(skb->data + IPFIELD_ALIGN_OFFSET);
if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) && tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) {
lbs_pr_info("Firmware ready event received\n");
wake_up(&cardp->fw_wq);
} else {
lbs_deb_usb("Waiting for confirmation; got %x %x\n", le32_to_cpu(tmp[0]), le32_to_cpu(tmp[1]));
if_usb_submit_rx_urb_fwload(cardp);
}
kfree_skb(skb);
return;
}
if (cardp->bootcmdresp <= 0) {
memcpy(&bootcmdresp, skb->data + IPFIELD_ALIGN_OFFSET, sizeof(bootcmdresp));
if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
kfree_skb(skb);
if_usb_submit_rx_urb_fwload(cardp);
cardp->bootcmdresp = BOOT_CMD_RESP_OK;
lbs_deb_usbd(&cardp->udev->dev, "Received valid boot command response\n");
return;
}
if (bootcmdresp.magic != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
if (bootcmdresp.magic == cpu_to_le32(CMD_TYPE_REQUEST) || bootcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) || bootcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) {
if (!cardp->bootcmdresp) lbs_pr_info("Firmware already seems alive; resetting\n");
cardp->bootcmdresp = -1;
} else {
lbs_pr_info("boot cmd response wrong magic number (0x%x)\n", le32_to_cpu(bootcmdresp.magic));
}
} else if ((bootcmdresp.cmd != BOOT_CMD_FW_BY_USB) && (bootcmdresp.cmd != BOOT_CMD_UPDATE_FW) && (bootcmdresp.cmd != BOOT_CMD_UPDATE_BOOT2)) {
lbs_pr_info("boot cmd response cmd_tag error (%d)\n", bootcmdresp.cmd);
} else if (bootcmdresp.result != BOOT_CMD_RESP_OK) {
lbs_pr_info("boot cmd response result error (%d)\n", bootcmdresp.result);
} else {
cardp->bootcmdresp = 1;
lbs_deb_usbd(&cardp->udev->dev, "Received valid boot command response\n");
}
kfree_skb(skb);
if_usb_submit_rx_urb_fwload(cardp);
return;
}
- syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
+ syncfwheader = kmemdup(skb->data + IPFIELD_ALIGN_OFFSET, sizeof(struct fwsyncheader), GFP_ATOMIC);
if (!syncfwheader) {
lbs_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
kfree_skb(skb);
return;
}
- memcpy(syncfwheader, skb->data + IPFIELD_ALIGN_OFFSET, sizeof(struct fwsyncheader));
if (!syncfwheader->cmd) {
lbs_deb_usb2(&cardp->udev->dev, "FW received Blk with correct CRC\n");
lbs_deb_usb2(&cardp->udev->dev, "FW received Blk seqnum = %d\n", le32_to_cpu(syncfwheader->seqnum));
cardp->CRC_OK = 1;
} else {
lbs_deb_usbd(&cardp->udev->dev, "FW received Blk with CRC error\n");
cardp->CRC_OK = 0;
}
kfree_skb(skb);
/* Give device 5s to either write firmware to its RAM or eeprom */
mod_timer(&cardp->fw_timeout, jiffies + (HZ * 5));
if (cardp->fwfinalblk) {
cardp->fwdnldover = 1;
goto exit;
}
if_usb_send_fw_pkt(cardp);
exit:
if_usb_submit_rx_urb_fwload(cardp);
kfree(syncfwheader);
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 664 |
--- initial
+++ final
@@ -1,27 +1,26 @@
static int wl1251_fetch_nvs(struct wl1251 *wl) {
const struct firmware *fw;
struct device *dev = wiphy_dev(wl->hw->wiphy);
int ret;
ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
if (ret < 0) {
wl1251_error("could not get nvs file: %d", ret);
return ret;
}
if (fw->size % 4) {
wl1251_error("nvs size is not multiple of 32 bits: %zu", fw->size);
ret = -EILSEQ;
goto out;
}
wl->nvs_len = fw->size;
- wl->nvs = kmalloc(wl->nvs_len, GFP_KERNEL);
+ wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL);
if (!wl->nvs) {
wl1251_error("could not allocate memory for the nvs file");
ret = -ENOMEM;
goto out;
}
- memcpy(wl->nvs, fw->data, wl->nvs_len);
ret = 0;
out:
release_firmware(fw);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 665 |
--- initial
+++ final
@@ -1,26 +1,25 @@
static int queue_dbg_open(struct inode *inode, struct file *file) {
struct usba_ep *ep = inode->i_private;
struct usba_request *req, *req_copy;
struct list_head *queue_data;
queue_data = kmalloc(sizeof(*queue_data), GFP_KERNEL);
if (!queue_data) return -ENOMEM;
INIT_LIST_HEAD(queue_data);
spin_lock_irq(&ep->udc->lock);
list_for_each_entry(req, &ep->queue, queue) {
- req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC);
+ req_copy = kmemdup(req, sizeof(*req_copy), GFP_ATOMIC);
if (!req_copy) goto fail;
- memcpy(req_copy, req, sizeof(*req_copy));
list_add_tail(&req_copy->queue, queue_data);
}
spin_unlock_irq(&ep->udc->lock);
file->private_data = queue_data;
return 0;
fail:
spin_unlock_irq(&ep->udc->lock);
list_for_each_entry_safe(req, req_copy, queue_data, queue) {
list_del(&req->queue);
kfree(req);
}
kfree(queue_data);
return -ENOMEM;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 666 |
--- initial
+++ final
@@ -1,86 +1,85 @@
static void if_usb_receive_fwload(struct urb *urb) {
struct if_usb_card *cardp = urb->context;
struct sk_buff *skb = cardp->rx_skb;
struct fwsyncheader *syncfwheader;
struct bootcmdresp bcmdresp;
lbtf_deb_enter(LBTF_DEB_USB);
if (urb->status) {
lbtf_deb_usbd(&cardp->udev->dev, "URB status is failed during fw load\n");
kfree_skb(skb);
lbtf_deb_leave(LBTF_DEB_USB);
return;
}
if (cardp->fwdnldover) {
__le32 *tmp = (__le32 *)(skb->data);
if (tmp[0] == cpu_to_le32(CMD_TYPE_INDICATION) && tmp[1] == cpu_to_le32(MACREG_INT_CODE_FIRMWARE_READY)) {
/* Firmware ready event received */
pr_info("Firmware ready event received\n");
wake_up(&cardp->fw_wq);
} else {
lbtf_deb_usb("Waiting for confirmation; got %x %x\n", le32_to_cpu(tmp[0]), le32_to_cpu(tmp[1]));
if_usb_submit_rx_urb_fwload(cardp);
}
kfree_skb(skb);
lbtf_deb_leave(LBTF_DEB_USB);
return;
}
if (cardp->bootcmdresp <= 0) {
memcpy(&bcmdresp, skb->data, sizeof(bcmdresp));
if (le16_to_cpu(cardp->udev->descriptor.bcdDevice) < 0x3106) {
kfree_skb(skb);
if_usb_submit_rx_urb_fwload(cardp);
cardp->bootcmdresp = 1;
/* Received valid boot command response */
lbtf_deb_usbd(&cardp->udev->dev, "Received valid boot command response\n");
lbtf_deb_leave(LBTF_DEB_USB);
return;
}
if (bcmdresp.magic != cpu_to_le32(BOOT_CMD_MAGIC_NUMBER)) {
if (bcmdresp.magic == cpu_to_le32(CMD_TYPE_REQUEST) || bcmdresp.magic == cpu_to_le32(CMD_TYPE_DATA) || bcmdresp.magic == cpu_to_le32(CMD_TYPE_INDICATION)) {
if (!cardp->bootcmdresp) pr_info("Firmware already seems alive; resetting\n");
cardp->bootcmdresp = -1;
} else {
pr_info("boot cmd response wrong magic number (0x%x)\n", le32_to_cpu(bcmdresp.magic));
}
} else if (bcmdresp.cmd != BOOT_CMD_FW_BY_USB) {
pr_info("boot cmd response cmd_tag error (%d)\n", bcmdresp.cmd);
} else if (bcmdresp.result != BOOT_CMD_RESP_OK) {
pr_info("boot cmd response result error (%d)\n", bcmdresp.result);
} else {
cardp->bootcmdresp = 1;
lbtf_deb_usbd(&cardp->udev->dev, "Received valid boot command response\n");
}
kfree_skb(skb);
if_usb_submit_rx_urb_fwload(cardp);
lbtf_deb_leave(LBTF_DEB_USB);
return;
}
- syncfwheader = kmalloc(sizeof(struct fwsyncheader), GFP_ATOMIC);
+ syncfwheader = kmemdup(skb->data, sizeof(struct fwsyncheader), GFP_ATOMIC);
if (!syncfwheader) {
lbtf_deb_usbd(&cardp->udev->dev, "Failure to allocate syncfwheader\n");
kfree_skb(skb);
lbtf_deb_leave(LBTF_DEB_USB);
return;
}
- memcpy(syncfwheader, skb->data, sizeof(struct fwsyncheader));
if (!syncfwheader->cmd) {
lbtf_deb_usb2(&cardp->udev->dev, "FW received Blk with correct CRC\n");
lbtf_deb_usb2(&cardp->udev->dev, "FW received Blk seqnum = %d\n", le32_to_cpu(syncfwheader->seqnum));
cardp->CRC_OK = 1;
} else {
lbtf_deb_usbd(&cardp->udev->dev, "FW received Blk with CRC error\n");
cardp->CRC_OK = 0;
}
kfree_skb(skb);
/* reschedule timer for 200ms hence */
mod_timer(&cardp->fw_timeout, jiffies + (HZ / 5));
if (cardp->fwfinalblk) {
cardp->fwdnldover = 1;
goto exit;
}
if_usb_send_fw_pkt(cardp);
exit:
if_usb_submit_rx_urb_fwload(cardp);
kfree(syncfwheader);
lbtf_deb_leave(LBTF_DEB_USB);
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 667 |
--- initial
+++ final
@@ -1,59 +1,58 @@
int __init acpi_ec_ecdt_probe(void) {
acpi_status status;
struct acpi_ec *saved_ec = NULL;
struct acpi_table_ecdt *ecdt_ptr;
boot_ec = make_acpi_ec();
if (!boot_ec) return -ENOMEM;
/*
* Generate a boot ec context
*/
dmi_check_system(ec_dmi_table);
status = acpi_get_table(ACPI_SIG_ECDT, 1, (struct acpi_table_header **)&ecdt_ptr);
if (ACPI_SUCCESS(status)) {
pr_info(PREFIX "EC description table is found, configuring boot EC\n");
boot_ec->command_addr = ecdt_ptr->control.address;
boot_ec->data_addr = ecdt_ptr->data.address;
boot_ec->gpe = ecdt_ptr->gpe;
boot_ec->handle = ACPI_ROOT_OBJECT;
acpi_get_handle(ACPI_ROOT_OBJECT, ecdt_ptr->id, &boot_ec->handle);
/* Don't trust ECDT, which comes from ASUSTek */
if (!EC_FLAGS_VALIDATE_ECDT) goto install;
- saved_ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL);
+ saved_ec = kmemdup(boot_ec, sizeof(struct acpi_ec), GFP_KERNEL);
if (!saved_ec) return -ENOMEM;
- memcpy(saved_ec, boot_ec, sizeof(struct acpi_ec));
/* fall through */
}
if (EC_FLAGS_SKIP_DSDT_SCAN) return -ENODEV;
/* This workaround is needed only on some broken machines,
* which require early EC, but fail to provide ECDT */
printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n");
status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, boot_ec, NULL);
/* Check that acpi_get_devices actually find something */
if (ACPI_FAILURE(status) || !boot_ec->handle) goto error;
if (saved_ec) {
/* try to find good ECDT from ASUSTek */
if (saved_ec->command_addr != boot_ec->command_addr || saved_ec->data_addr != boot_ec->data_addr || saved_ec->gpe != boot_ec->gpe || saved_ec->handle != boot_ec->handle)
pr_info(PREFIX "ASUSTek keeps feeding us with broken "
"ECDT tables, which are very hard to workaround. "
"Trying to use DSDT EC info instead. Please send "
"output of acpidump to [email protected]\n");
kfree(saved_ec);
saved_ec = NULL;
} else {
/* We really need to limit this workaround, the only ASUS,
* which needs it, has fake EC._INI method, so use it as flag.
* Keep boot_ec struct as it will be needed soon.
*/
acpi_handle dummy;
if (!dmi_name_in_vendors("ASUS") || ACPI_FAILURE(acpi_get_handle(boot_ec->handle, "_INI", &dummy))) return -ENODEV;
}
install:
if (!ec_install_handlers(boot_ec)) {
first_ec = boot_ec;
return 0;
}
error:
kfree(boot_ec);
boot_ec = NULL;
return -ENODEV;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 668 |
--- initial
+++ final
@@ -1,83 +1,82 @@
struct ieee80211_hw *wl1271_alloc_hw(void) {
struct ieee80211_hw *hw;
struct platform_device *plat_dev = NULL;
struct wl1271 *wl;
int i, ret;
hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
if (!hw) {
wl1271_error("could not alloc ieee80211_hw");
ret = -ENOMEM;
goto err_hw_alloc;
}
- plat_dev = kmalloc(sizeof(wl1271_device), GFP_KERNEL);
+ plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL);
if (!plat_dev) {
wl1271_error("could not allocate platform_device");
ret = -ENOMEM;
goto err_plat_alloc;
}
- memcpy(plat_dev, &wl1271_device, sizeof(wl1271_device));
wl = hw->priv;
memset(wl, 0, sizeof(*wl));
INIT_LIST_HEAD(&wl->list);
wl->hw = hw;
wl->plat_dev = plat_dev;
skb_queue_head_init(&wl->tx_queue);
INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
wl->channel = WL1271_DEFAULT_CHANNEL;
wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
wl->default_key = 0;
wl->rx_counter = 0;
wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
wl->psm_entry_retry = 0;
wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
wl->rate_set = CONF_TX_RATE_MASK_BASIC;
wl->sta_rate_set = 0;
wl->band = IEEE80211_BAND_2GHZ;
wl->vif = NULL;
wl->flags = 0;
wl->sg_enabled = true;
wl->hw_pg_ver = -1;
for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
wl->tx_frames[i] = NULL;
spin_lock_init(&wl->wl_lock);
wl->state = WL1271_STATE_OFF;
mutex_init(&wl->mutex);
/* Apply default driver configuration. */
wl1271_conf_init(wl);
wl1271_debugfs_init(wl);
/* Register platform device */
ret = platform_device_register(wl->plat_dev);
if (ret) {
wl1271_error("couldn't register platform device");
goto err_hw;
}
dev_set_drvdata(&wl->plat_dev->dev, wl);
/* Create sysfs file to control bt coex state */
ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
if (ret < 0) {
wl1271_error("failed to create sysfs file bt_coex_state");
goto err_platform;
}
/* Create sysfs file to get HW PG version */
ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
if (ret < 0) {
wl1271_error("failed to create sysfs file hw_pg_ver");
goto err_bt_coex_state;
}
return hw;
err_bt_coex_state:
device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
err_platform:
platform_device_unregister(wl->plat_dev);
err_hw:
wl1271_debugfs_exit(wl);
kfree(plat_dev);
err_plat_alloc:
ieee80211_free_hw(hw);
err_hw_alloc:
return ERR_PTR(ret);
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 669 |
--- initial
+++ final
@@ -1,17 +1,16 @@
static struct iwm_rx_ticket_node *iwm_rx_ticket_node_alloc(struct iwm_priv *iwm, struct iwm_rx_ticket *ticket) {
struct iwm_rx_ticket_node *ticket_node;
ticket_node = kzalloc(sizeof(struct iwm_rx_ticket_node), GFP_KERNEL);
if (!ticket_node) {
IWM_ERR(iwm, "Couldn't allocate ticket node\n");
return ERR_PTR(-ENOMEM);
}
- ticket_node->ticket = kzalloc(sizeof(struct iwm_rx_ticket), GFP_KERNEL);
+ ticket_node->ticket = kmemdup(ticket, sizeof(struct iwm_rx_ticket), GFP_KERNEL);
if (!ticket_node->ticket) {
IWM_ERR(iwm, "Couldn't allocate RX ticket\n");
kfree(ticket_node);
return ERR_PTR(-ENOMEM);
}
- memcpy(ticket_node->ticket, ticket, sizeof(struct iwm_rx_ticket));
INIT_LIST_HEAD(&ticket_node->node);
return ticket_node;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 670 |
--- initial
+++ final
@@ -1,11 +1,10 @@
static void ath9k_hif_usb_reboot(struct usb_device *udev) {
u32 reboot_cmd = 0xffffffff;
void *buf;
int ret;
- buf = kmalloc(4, GFP_KERNEL);
+ buf = kmemdup(&reboot_cmd, 4, GFP_KERNEL);
if (!buf) return;
- memcpy(buf, &reboot_cmd, 4);
ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE), buf, 4, NULL, HZ);
if (ret) dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
kfree(buf);
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 671 |
--- initial
+++ final
@@ -1,64 +1,62 @@
int nouveau_grctx_prog_load(struct drm_device *dev) {
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
const int chipset = dev_priv->chipset;
const struct firmware *fw;
const struct nouveau_ctxprog *cp;
const struct nouveau_ctxvals *cv;
char name[32];
int ret, i;
if (pgraph->accel_blocked) return -ENODEV;
if (!pgraph->ctxprog) {
sprintf(name, "nouveau/nv%02x.ctxprog", chipset);
ret = request_firmware(&fw, name, &dev->pdev->dev);
if (ret) {
NV_ERROR(dev, "No ctxprog for NV%02x\n", chipset);
return ret;
}
- pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL);
+ pgraph->ctxprog = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!pgraph->ctxprog) {
NV_ERROR(dev, "OOM copying ctxprog\n");
release_firmware(fw);
return -ENOMEM;
}
- memcpy(pgraph->ctxprog, fw->data, fw->size);
cp = pgraph->ctxprog;
if (le32_to_cpu(cp->signature) != 0x5043564e || cp->version != 0 || le16_to_cpu(cp->length) != ((fw->size - 7) / 4)) {
NV_ERROR(dev, "ctxprog invalid\n");
release_firmware(fw);
nouveau_grctx_fini(dev);
return -EINVAL;
}
release_firmware(fw);
}
if (!pgraph->ctxvals) {
sprintf(name, "nouveau/nv%02x.ctxvals", chipset);
ret = request_firmware(&fw, name, &dev->pdev->dev);
if (ret) {
NV_ERROR(dev, "No ctxvals for NV%02x\n", chipset);
nouveau_grctx_fini(dev);
return ret;
}
- pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL);
+ pgraph->ctxvals = kmemdup(fw->data, fw->size, GFP_KERNEL);
if (!pgraph->ctxvals) {
NV_ERROR(dev, "OOM copying ctxvals\n");
release_firmware(fw);
nouveau_grctx_fini(dev);
return -ENOMEM;
}
- memcpy(pgraph->ctxvals, fw->data, fw->size);
cv = (void *)pgraph->ctxvals;
if (le32_to_cpu(cv->signature) != 0x5643564e || cv->version != 0 || le32_to_cpu(cv->length) != ((fw->size - 9) / 8)) {
NV_ERROR(dev, "ctxvals invalid\n");
release_firmware(fw);
nouveau_grctx_fini(dev);
return -EINVAL;
}
release_firmware(fw);
}
cp = pgraph->ctxprog;
nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
for (i = 0; i < le16_to_cpu(cp->length); i++)
nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, le32_to_cpu(cp->data[i]));
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 672 |
--- initial
+++ final
@@ -1,20 +1,19 @@
static bool radeon_read_bios(struct radeon_device *rdev) {
uint8_t __iomem *bios;
size_t size;
rdev->bios = NULL;
/* XXX: some cards may return 0 for rom size? ddx has a workaround */
bios = pci_map_rom(rdev->pdev, &size);
if (!bios) { return false; }
if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
pci_unmap_rom(rdev->pdev, bios);
return false;
}
- rdev->bios = kmalloc(size, GFP_KERNEL);
+ rdev->bios = kmemdup(bios, size, GFP_KERNEL);
if (rdev->bios == NULL) {
pci_unmap_rom(rdev->pdev, bios);
return false;
}
- memcpy(rdev->bios, bios, size);
pci_unmap_rom(rdev->pdev, bios);
return true;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 673 |
--- initial
+++ final
@@ -1,65 +1,64 @@
static int bcm203x_probe(struct usb_interface *intf, const struct usb_device_id *id) {
const struct firmware *firmware;
struct usb_device *udev = interface_to_usbdev(intf);
struct bcm203x_data *data;
int size;
BT_DBG("intf %p id %p", intf, id);
if (intf->cur_altsetting->desc.bInterfaceNumber != 0) return -ENODEV;
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data) {
BT_ERR("Can't allocate memory for data structure");
return -ENOMEM;
}
data->udev = udev;
data->state = BCM203X_LOAD_MINIDRV;
data->urb = usb_alloc_urb(0, GFP_KERNEL);
if (!data->urb) {
BT_ERR("Can't allocate URB");
kfree(data);
return -ENOMEM;
}
if (request_firmware(&firmware, "BCM2033-MD.hex", &udev->dev) < 0) {
BT_ERR("Mini driver request failed");
usb_free_urb(data->urb);
kfree(data);
return -EIO;
}
BT_DBG("minidrv data %p size %zu", firmware->data, firmware->size);
size = max_t(uint, firmware->size, 4096);
data->buffer = kmalloc(size, GFP_KERNEL);
if (!data->buffer) {
BT_ERR("Can't allocate memory for mini driver");
release_firmware(firmware);
usb_free_urb(data->urb);
kfree(data);
return -ENOMEM;
}
memcpy(data->buffer, firmware->data, firmware->size);
usb_fill_bulk_urb(data->urb, udev, usb_sndbulkpipe(udev, BCM203X_OUT_EP), data->buffer, firmware->size, bcm203x_complete, data);
release_firmware(firmware);
if (request_firmware(&firmware, "BCM2033-FW.bin", &udev->dev) < 0) {
BT_ERR("Firmware request failed");
usb_free_urb(data->urb);
kfree(data->buffer);
kfree(data);
return -EIO;
}
BT_DBG("firmware data %p size %zu", firmware->data, firmware->size);
- data->fw_data = kmalloc(firmware->size, GFP_KERNEL);
+ data->fw_data = kmemdup(firmware->data, firmware->size, GFP_KERNEL);
if (!data->fw_data) {
BT_ERR("Can't allocate memory for firmware image");
release_firmware(firmware);
usb_free_urb(data->urb);
kfree(data->buffer);
kfree(data);
return -ENOMEM;
}
- memcpy(data->fw_data, firmware->data, firmware->size);
data->fw_size = firmware->size;
data->fw_sent = 0;
release_firmware(firmware);
INIT_WORK(&data->work, bcm203x_work);
usb_set_intfdata(intf, data);
schedule_work(&data->work);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 675 |
--- initial
+++ final
@@ -1,47 +1,46 @@
int hid_parse_report(struct hid_device *device, __u8 *start, unsigned size) {
struct hid_parser *parser;
struct hid_item item;
__u8 *end;
int ret;
static int (*dispatch_type[])(struct hid_parser * parser, struct hid_item * item) = {hid_parser_main, hid_parser_global, hid_parser_local, hid_parser_reserved};
if (device->driver->report_fixup) device->driver->report_fixup(device, start, size);
- device->rdesc = kmalloc(size, GFP_KERNEL);
+ device->rdesc = kmemdup(start, size, GFP_KERNEL);
if (device->rdesc == NULL) return -ENOMEM;
- memcpy(device->rdesc, start, size);
device->rsize = size;
parser = vmalloc(sizeof(struct hid_parser));
if (!parser) {
ret = -ENOMEM;
goto err;
}
memset(parser, 0, sizeof(struct hid_parser));
parser->device = device;
end = start + size;
ret = -EINVAL;
while ((start = fetch_item(start, end, &item)) != NULL) {
if (item.format != HID_ITEM_FORMAT_SHORT) {
dbg_hid("unexpected long global item\n");
goto err;
}
if (dispatch_type[item.type](parser, &item)) {
dbg_hid("item %u %u %u %u parsing failed\n", item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
goto err;
}
if (start == end) {
if (parser->collection_stack_ptr) {
dbg_hid("unbalanced collection at end of report description\n");
goto err;
}
if (parser->local.delimiter_depth) {
dbg_hid("unbalanced delimiter at end of report description\n");
goto err;
}
vfree(parser);
return 0;
}
}
dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
err:
vfree(parser);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 676 |
--- initial
+++ final
@@ -1,79 +1,78 @@
static int dma_tx_fragment(struct b43_dmaring *ring, struct sk_buff *skb) {
const struct b43_dma_ops *ops = ring->ops;
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct b43_private_tx_info *priv_info = b43_get_priv_tx_info(info);
u8 *header;
int slot, old_top_slot, old_used_slots;
int err;
struct b43_dmadesc_generic *desc;
struct b43_dmadesc_meta *meta;
struct b43_dmadesc_meta *meta_hdr;
u16 cookie;
size_t hdrsize = b43_txhdr_size(ring->dev);
/* Important note: If the number of used DMA slots per TX frame
* is changed here, the TX_SLOTS_PER_FRAME definition at the top of
* the file has to be updated, too!
*/
old_top_slot = ring->current_slot;
old_used_slots = ring->used_slots;
/* Get a slot for the header. */
slot = request_slot(ring);
desc = ops->idx2desc(ring, slot, &meta_hdr);
memset(meta_hdr, 0, sizeof(*meta_hdr));
header = &(ring->txhdr_cache[(slot / TX_SLOTS_PER_FRAME) * hdrsize]);
cookie = generate_cookie(ring, slot);
err = b43_generate_txhdr(ring->dev, header, skb, info, cookie);
if (unlikely(err)) {
ring->current_slot = old_top_slot;
ring->used_slots = old_used_slots;
return err;
}
meta_hdr->dmaaddr = map_descbuffer(ring, (unsigned char *)header, hdrsize, 1);
if (b43_dma_mapping_error(ring, meta_hdr->dmaaddr, hdrsize, 1)) {
ring->current_slot = old_top_slot;
ring->used_slots = old_used_slots;
return -EIO;
}
ops->fill_descriptor(ring, desc, meta_hdr->dmaaddr, hdrsize, 1, 0, 0);
/* Get a slot for the payload. */
slot = request_slot(ring);
desc = ops->idx2desc(ring, slot, &meta);
memset(meta, 0, sizeof(*meta));
meta->skb = skb;
meta->is_last_fragment = 1;
priv_info->bouncebuffer = NULL;
meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
/* create a bounce buffer in zone_dma on mapping failure. */
if (b43_dma_mapping_error(ring, meta->dmaaddr, skb->len, 1)) {
- priv_info->bouncebuffer = kmalloc(skb->len, GFP_ATOMIC | GFP_DMA);
+ priv_info->bouncebuffer = kmemdup(skb->data, skb->len, GFP_ATOMIC | GFP_DMA);
if (!priv_info->bouncebuffer) {
ring->current_slot = old_top_slot;
ring->used_slots = old_used_slots;
err = -ENOMEM;
goto out_unmap_hdr;
}
- memcpy(priv_info->bouncebuffer, skb->data, skb->len);
meta->dmaaddr = map_descbuffer(ring, priv_info->bouncebuffer, skb->len, 1);
if (b43_dma_mapping_error(ring, meta->dmaaddr, skb->len, 1)) {
kfree(priv_info->bouncebuffer);
priv_info->bouncebuffer = NULL;
ring->current_slot = old_top_slot;
ring->used_slots = old_used_slots;
err = -EIO;
goto out_unmap_hdr;
}
}
ops->fill_descriptor(ring, desc, meta->dmaaddr, skb->len, 0, 1, 1);
if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
/* Tell the firmware about the cookie of the last
* mcast frame, so it can clear the more-data bit in it. */
b43_shm_write16(ring->dev, B43_SHM_SHARED, B43_SHM_SH_MCASTCOOKIE, cookie);
}
/* Now transfer the whole frame. */
wmb();
ops->poke_tx(ring, next_slot(ring, slot));
return 0;
out_unmap_hdr:
unmap_descbuffer(ring, meta_hdr->dmaaddr, hdrsize, 1);
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 677 |
--- initial
+++ final
@@ -1,25 +1,24 @@
static int ipw_wx_set_genie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) {
struct ipw_priv *priv = libipw_priv(dev);
struct libipw_device *ieee = priv->ieee;
u8 *buf;
int err = 0;
if (wrqu->data.length > MAX_WPA_IE_LEN || (wrqu->data.length && extra == NULL)) return -EINVAL;
if (wrqu->data.length) {
- buf = kmalloc(wrqu->data.length, GFP_KERNEL);
+ buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
if (buf == NULL) {
err = -ENOMEM;
goto out;
}
- memcpy(buf, extra, wrqu->data.length);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = wrqu->data.length;
} else {
kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
out:
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 678 |
--- initial
+++ final
@@ -1,41 +1,39 @@
int pohmelfs_copy_crypto(struct pohmelfs_sb *psb) {
struct pohmelfs_config_group *g;
int err = -ENOENT;
mutex_lock(&pohmelfs_config_lock);
g = pohmelfs_find_config_group(psb->idx);
if (!g) goto err_out_exit;
if (g->hash_string) {
err = -ENOMEM;
psb->hash_string = kstrdup(g->hash_string, GFP_KERNEL);
if (!psb->hash_string) goto err_out_exit;
psb->hash_strlen = g->hash_strlen;
}
if (g->cipher_string) {
psb->cipher_string = kstrdup(g->cipher_string, GFP_KERNEL);
if (!psb->cipher_string) goto err_out_free_hash_string;
psb->cipher_strlen = g->cipher_strlen;
}
if (g->hash_keysize) {
- psb->hash_key = kmalloc(g->hash_keysize, GFP_KERNEL);
+ psb->hash_key = kmemdup(g->hash_key, g->hash_keysize, GFP_KERNEL);
if (!psb->hash_key) goto err_out_free_cipher_string;
- memcpy(psb->hash_key, g->hash_key, g->hash_keysize);
psb->hash_keysize = g->hash_keysize;
}
if (g->cipher_keysize) {
- psb->cipher_key = kmalloc(g->cipher_keysize, GFP_KERNEL);
+ psb->cipher_key = kmemdup(g->cipher_key, g->cipher_keysize, GFP_KERNEL);
if (!psb->cipher_key) goto err_out_free_hash;
- memcpy(psb->cipher_key, g->cipher_key, g->cipher_keysize);
psb->cipher_keysize = g->cipher_keysize;
}
mutex_unlock(&pohmelfs_config_lock);
return 0;
err_out_free_hash:
kfree(psb->hash_key);
err_out_free_cipher_string:
kfree(psb->cipher_string);
err_out_free_hash_string:
kfree(psb->hash_string);
err_out_exit:
mutex_unlock(&pohmelfs_config_lock);
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 679 |
--- initial
+++ final
@@ -1,16 +1,15 @@
static int pohmelfs_crypto_cipher_init(struct pohmelfs_config_group *g, struct pohmelfs_crypto *c) {
char *algo = (char *)c->data;
u8 *key = (u8 *)(algo + c->strlen);
if (g->cipher_string) return -EEXIST;
g->cipher_string = kstrdup(algo, GFP_KERNEL);
if (!g->cipher_string) return -ENOMEM;
g->cipher_strlen = c->strlen;
g->cipher_keysize = c->keysize;
- g->cipher_key = kmalloc(c->keysize, GFP_KERNEL);
+ g->cipher_key = kmemdup(key, c->keysize, GFP_KERNEL);
if (!g->cipher_key) {
kfree(g->cipher_string);
return -ENOMEM;
}
- memcpy(g->cipher_key, key, c->keysize);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 680 |
--- initial
+++ final
@@ -1,16 +1,15 @@
static int pohmelfs_crypto_hash_init(struct pohmelfs_config_group *g, struct pohmelfs_crypto *c) {
char *algo = (char *)c->data;
u8 *key = (u8 *)(algo + c->strlen);
if (g->hash_string) return -EEXIST;
g->hash_string = kstrdup(algo, GFP_KERNEL);
if (!g->hash_string) return -ENOMEM;
g->hash_strlen = c->strlen;
g->hash_keysize = c->keysize;
- g->hash_key = kmalloc(c->keysize, GFP_KERNEL);
+ g->hash_key = kmemdup(key, c->keysize, GFP_KERNEL);
if (!g->hash_key) {
kfree(g->hash_string);
return -ENOMEM;
}
- memcpy(g->hash_key, key, c->keysize);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 681 |
--- initial
+++ final
@@ -1,7 +1,6 @@
int line6_dumpreq_initbuf(struct line6_dump_request *l6dr, const void *buf, size_t len, int num) {
- l6dr->reqbufs[num].buffer = kmalloc(len, GFP_KERNEL);
+ l6dr->reqbufs[num].buffer = kmemdup(buf, len, GFP_KERNEL);
if (l6dr->reqbufs[num].buffer == NULL) return -ENOMEM;
- memcpy(l6dr->reqbufs[num].buffer, buf, len);
l6dr->reqbufs[num].length = len;
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 682 |
--- initial
+++ final
@@ -1,18 +1,17 @@
static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee, struct ieee_param *param, int plen) {
u8 *buf;
if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) return -EINVAL;
if (param->u.wpa_ie.len) {
- buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
+ buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = param->u.wpa_ie.len;
} else {
kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 683 |
--- initial
+++ final
@@ -1,24 +1,23 @@
int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) {
u8 *buf;
if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
// printk("return error out, len:%d\n", len);
return -EINVAL;
}
if (len) {
if (len != ie[1] + 2) {
printk("len: %Zd, ie:%d\n", len, ie[1]);
return -EINVAL;
}
- buf = kmalloc(len, GFP_KERNEL);
+ buf = kmemdup(ie, len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, ie, len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = len;
} else {
if (ieee->wpa_ie) kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 684 |
--- initial
+++ final
@@ -1,20 +1,19 @@
static inline u16 auth_parse(struct sk_buff *skb, u8 **challenge, int *chlen) {
struct ieee80211_authentication *a;
u8 *t;
if (skb->len < (sizeof(struct ieee80211_authentication) - sizeof(struct ieee80211_info_element))) {
IEEE80211_DEBUG_MGMT("invalid len in auth resp: %d\n", skb->len);
return 0xcafe;
}
*challenge = NULL;
a = (struct ieee80211_authentication *)skb->data;
if (skb->len > (sizeof(struct ieee80211_authentication) + 3)) {
t = skb->data + sizeof(struct ieee80211_authentication);
if (*(t++) == MFIE_TYPE_CHALLENGE) {
*chlen = *(t++);
- *challenge = kmalloc(*chlen, GFP_ATOMIC);
+ *challenge = kmemdup(t, *chlen, GFP_ATOMIC);
if (!*challenge) return -ENOMEM;
- memcpy(*challenge, t, *chlen);
}
}
return cpu_to_le16(a->status);
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 685 |
--- initial
+++ final
@@ -1,18 +1,17 @@
static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee, struct ieee_param *param, int plen) {
u8 *buf;
if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) return -EINVAL;
if (param->u.wpa_ie.len) {
- buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
+ buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = param->u.wpa_ie.len;
} else {
kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 686 |
--- initial
+++ final
@@ -1,24 +1,23 @@
int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) {
u8 *buf;
if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
// printk("return error out, len:%d\n", len);
return -EINVAL;
}
if (len) {
if (len != ie[1] + 2) {
printk("len:%zu, ie:%d\n", len, ie[1]);
return -EINVAL;
}
- buf = kmalloc(len, GFP_KERNEL);
+ buf = kmemdup(ie, len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, ie, len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = len;
} else {
if (ieee->wpa_ie) kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 687 |
--- initial
+++ final
@@ -1,65 +1,64 @@
int pod_init(struct usb_interface *interface, struct usb_line6_pod *pod) {
int err;
struct usb_line6 *line6 = &pod->line6;
if ((interface == NULL) || (pod == NULL)) return -ENODEV;
pod->channel_num = 255;
/* initialize wait queues: */
init_waitqueue_head(&pod->monitor_level.wait);
init_waitqueue_head(&pod->routing.wait);
init_waitqueue_head(&pod->tuner_mute.wait);
init_waitqueue_head(&pod->tuner_freq.wait);
init_waitqueue_head(&pod->tuner_note.wait);
init_waitqueue_head(&pod->tuner_pitch.wait);
init_waitqueue_head(&pod->clipping.wait);
memset(pod->param_dirty, 0xff, sizeof(pod->param_dirty));
/* initialize USB buffers: */
err = line6_dumpreq_init(&pod->dumpreq, pod_request_channel, sizeof(pod_request_channel));
if (err < 0) {
dev_err(&interface->dev, "Out of memory\n");
pod_destruct(interface);
return -ENOMEM;
}
- pod->buffer_versionreq = kmalloc(sizeof(pod_request_version), GFP_KERNEL);
+ pod->buffer_versionreq = kmemdup(pod_request_version, sizeof(pod_request_version), GFP_KERNEL);
if (pod->buffer_versionreq == NULL) {
dev_err(&interface->dev, "Out of memory\n");
pod_destruct(interface);
return -ENOMEM;
}
- memcpy(pod->buffer_versionreq, pod_request_version, sizeof(pod_request_version));
/* create sysfs entries: */
err = pod_create_files2(&interface->dev);
if (err < 0) {
pod_destruct(interface);
return err;
}
/* initialize audio system: */
err = line6_init_audio(line6);
if (err < 0) {
pod_destruct(interface);
return err;
}
/* initialize MIDI subsystem: */
err = line6_init_midi(line6);
if (err < 0) {
pod_destruct(interface);
return err;
}
/* initialize PCM subsystem: */
err = line6_init_pcm(line6, &pod_pcm_properties);
if (err < 0) {
pod_destruct(interface);
return err;
}
/* register audio system: */
err = line6_register_audio(line6);
if (err < 0) {
pod_destruct(interface);
return err;
}
if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
/* query some data: */
line6_startup_delayed(&pod->dumpreq, POD_STARTUP_DELAY, pod_startup_timeout, pod);
line6_read_serial_number(&pod->line6, &pod->serial_number);
}
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 688 |
--- initial
+++ final
@@ -1,18 +1,17 @@
static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee, struct ieee_param *param, int plen) {
u8 *buf;
if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) return -EINVAL;
if (param->u.wpa_ie.len) {
- buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
+ buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = param->u.wpa_ie.len;
} else {
kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 689 |
--- initial
+++ final
@@ -1,25 +1,24 @@
int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) {
u8 *buf = NULL;
if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
printk("return error out, len:%zu\n", len);
return -EINVAL;
}
if (len) {
if (len != ie[1] + 2) {
printk("len:%zu, ie:%d\n", len, ie[1]);
return -EINVAL;
}
- buf = kmalloc(len, GFP_KERNEL);
+ buf = kmemdup(ie, len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, ie, len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = len;
} else {
if (ieee->wpa_ie) kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
// printk("<=====out %s()\n", __func__);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 690 |
--- initial
+++ final
@@ -1,18 +1,17 @@
static int ieee80211_wpa_set_wpa_ie(struct ieee80211_device *ieee, struct ieee_param *param, int plen) {
u8 *buf;
if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) return -EINVAL;
if (param->u.wpa_ie.len) {
- buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
+ buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = param->u.wpa_ie.len;
} else {
kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
ieee80211_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 691 |
--- initial
+++ final
@@ -1,35 +1,34 @@
int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len) {
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)
#if 0
printk("====>%s()\n", __FUNCTION__);
{
int i;
for (i=0; i<len; i++)
printk("%2x ", ie[i]&0xff);
printk("\n");
}
#endif
u8 *buf;
if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
// printk("return error out, len:%d\n", len);
return -EINVAL;
}
if (len) {
if (len != ie[1] + 2) {
printk("len:%zu, ie:%d\n", len, ie[1]);
return -EINVAL;
}
- buf = kmalloc(len, GFP_KERNEL);
+ buf = kmemdup(ie, len, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, ie, len);
kfree(ieee->wpa_ie);
ieee->wpa_ie = buf;
ieee->wpa_ie_len = len;
} else {
if (ieee->wpa_ie) kfree(ieee->wpa_ie);
ieee->wpa_ie = NULL;
ieee->wpa_ie_len = 0;
}
#endif
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 692 |
--- initial
+++ final
@@ -1,62 +1,61 @@
static void stub_recv_cmd_submit(struct stub_device *sdev, struct usbip_header *pdu) {
int ret;
struct stub_priv *priv;
struct usbip_device *ud = &sdev->ud;
struct usb_device *udev = interface_to_usbdev(sdev->interface);
int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction);
priv = stub_priv_alloc(sdev, pdu);
if (!priv) return;
/* setup a urb */
if (usb_pipeisoc(pipe))
priv->urb = usb_alloc_urb(pdu->u.cmd_submit.number_of_packets, GFP_KERNEL);
else
priv->urb = usb_alloc_urb(0, GFP_KERNEL);
if (!priv->urb) {
dev_err(&sdev->interface->dev, "malloc urb\n");
usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
return;
}
/* set priv->urb->transfer_buffer */
if (pdu->u.cmd_submit.transfer_buffer_length > 0) {
priv->urb->transfer_buffer = kzalloc(pdu->u.cmd_submit.transfer_buffer_length, GFP_KERNEL);
if (!priv->urb->transfer_buffer) {
dev_err(&sdev->interface->dev, "malloc x_buff\n");
usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
return;
}
}
/* set priv->urb->setup_packet */
- priv->urb->setup_packet = kzalloc(8, GFP_KERNEL);
+ priv->urb->setup_packet = kmemdup(&pdu->u.cmd_submit.setup, 8, GFP_KERNEL);
if (!priv->urb->setup_packet) {
dev_err(&sdev->interface->dev, "allocate setup_packet\n");
usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
return;
}
- memcpy(priv->urb->setup_packet, &pdu->u.cmd_submit.setup, 8);
/* set other members from the base header of pdu */
priv->urb->context = (void *)priv;
priv->urb->dev = udev;
priv->urb->pipe = pipe;
priv->urb->complete = stub_complete;
usbip_pack_pdu(pdu, priv->urb, USBIP_CMD_SUBMIT, 0);
if (usbip_recv_xbuff(ud, priv->urb) < 0) return;
if (usbip_recv_iso(ud, priv->urb) < 0) return;
/* no need to submit an intercepted request, but harmless? */
tweak_special_requests(priv->urb);
/* urb is now ready to submit */
ret = usb_submit_urb(priv->urb, GFP_KERNEL);
if (ret == 0)
usbip_dbg_stub_rx("submit urb ok, seqnum %u\n", pdu->base.seqnum);
else {
dev_err(&sdev->interface->dev, "submit_urb error, %d\n", ret);
usbip_dump_header(pdu);
usbip_dump_urb(priv->urb);
/*
* Pessimistic.
* This connection will be discarded.
*/
usbip_event_add(ud, SDEV_EVENT_ERROR_SUBMIT);
}
usbip_dbg_stub_rx("Leave\n");
return;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 693 |
--- initial
+++ final
@@ -1,36 +1,35 @@
static int firmwareUpload(struct usbduxsub *usbduxsub, const u8 *firmwareBinary, int sizeFirmware) {
int ret;
uint8_t *fwBuf;
if (!firmwareBinary) return 0;
if (sizeFirmware > FIRMWARE_MAX_LEN) {
dev_err(&usbduxsub->interface->dev, "usbdux firmware binary it too large for FX2.\n");
return -ENOMEM;
}
/* we generate a local buffer for the firmware */
- fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
+ fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
if (!fwBuf) {
dev_err(&usbduxsub->interface->dev, "comedi_: mem alloc for firmware failed\n");
return -ENOMEM;
}
- memcpy(fwBuf, firmwareBinary, sizeFirmware);
ret = usbduxsub_stop(usbduxsub);
if (ret < 0) {
dev_err(&usbduxsub->interface->dev, "comedi_: can not stop firmware\n");
kfree(fwBuf);
return ret;
}
ret = usbduxsub_upload(usbduxsub, fwBuf, 0, sizeFirmware);
if (ret < 0) {
dev_err(&usbduxsub->interface->dev, "comedi_: firmware upload failed\n");
kfree(fwBuf);
return ret;
}
ret = usbduxsub_start(usbduxsub);
if (ret < 0) {
dev_err(&usbduxsub->interface->dev, "comedi_: can not start firmware\n");
kfree(fwBuf);
return ret;
}
kfree(fwBuf);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 694 |
--- initial
+++ final
@@ -1,36 +1,35 @@
static int firmwareUpload(struct usbduxfastsub_s *usbduxfastsub, const u8 *firmwareBinary, int sizeFirmware) {
int ret;
uint8_t *fwBuf;
if (!firmwareBinary) return 0;
if (sizeFirmware > FIRMWARE_MAX_LEN) {
dev_err(&usbduxfastsub->interface->dev, "comedi_: usbduxfast firmware binary it too large for FX2.\n");
return -ENOMEM;
}
/* we generate a local buffer for the firmware */
- fwBuf = kzalloc(sizeFirmware, GFP_KERNEL);
+ fwBuf = kmemdup(firmwareBinary, sizeFirmware, GFP_KERNEL);
if (!fwBuf) {
dev_err(&usbduxfastsub->interface->dev, "comedi_: mem alloc for firmware failed\n");
return -ENOMEM;
}
- memcpy(fwBuf, firmwareBinary, sizeFirmware);
ret = usbduxfastsub_stop(usbduxfastsub);
if (ret < 0) {
dev_err(&usbduxfastsub->interface->dev, "comedi_: can not stop firmware\n");
kfree(fwBuf);
return ret;
}
ret = usbduxfastsub_upload(usbduxfastsub, fwBuf, 0, sizeFirmware);
if (ret < 0) {
dev_err(&usbduxfastsub->interface->dev, "comedi_: firmware upload failed\n");
kfree(fwBuf);
return ret;
}
ret = usbduxfastsub_start(usbduxfastsub);
if (ret < 0) {
dev_err(&usbduxfastsub->interface->dev, "comedi_: can not start firmware\n");
kfree(fwBuf);
return ret;
}
kfree(fwBuf);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 695 |
--- initial
+++ final
@@ -1,63 +1,62 @@
int variax_init(struct usb_interface *interface, struct usb_line6_variax *variax) {
int err;
if ((interface == NULL) || (variax == NULL)) return -ENODEV;
/* initialize USB buffers: */
err = line6_dumpreq_init(&variax->dumpreq, variax_request_model1, sizeof(variax_request_model1));
if (err < 0) {
dev_err(&interface->dev, "Out of memory\n");
variax_destruct(interface);
return err;
}
err = line6_dumpreq_initbuf(&variax->dumpreq, variax_request_model2, sizeof(variax_request_model2), 1);
if (err < 0) {
dev_err(&interface->dev, "Out of memory\n");
variax_destruct(interface);
return err;
}
err = line6_dumpreq_initbuf(&variax->dumpreq, variax_request_bank, sizeof(variax_request_bank), 2);
if (err < 0) {
dev_err(&interface->dev, "Out of memory\n");
variax_destruct(interface);
return err;
}
- variax->buffer_activate = kmalloc(sizeof(variax_activate), GFP_KERNEL);
+ variax->buffer_activate = kmemdup(variax_activate, sizeof(variax_activate), GFP_KERNEL);
if (variax->buffer_activate == NULL) {
dev_err(&interface->dev, "Out of memory\n");
variax_destruct(interface);
return -ENOMEM;
}
- memcpy(variax->buffer_activate, variax_activate, sizeof(variax_activate));
init_timer(&variax->activate_timer);
/* create sysfs entries: */
err = variax_create_files(0, 0, &interface->dev);
if (err < 0) {
variax_destruct(interface);
return err;
}
err = variax_create_files2(&interface->dev);
if (err < 0) {
variax_destruct(interface);
return err;
}
/* initialize audio system: */
err = line6_init_audio(&variax->line6);
if (err < 0) {
variax_destruct(interface);
return err;
}
/* initialize MIDI subsystem: */
err = line6_init_midi(&variax->line6);
if (err < 0) {
variax_destruct(interface);
return err;
}
/* register audio system: */
err = line6_register_audio(&variax->line6);
if (err < 0) {
variax_destruct(interface);
return err;
}
variax_activate_delayed(variax, VARIAX_ACTIVATE_DELAY);
line6_startup_delayed(&variax->dumpreq, VARIAX_STARTUP_DELAY, variax_startup_timeout, variax);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 696 |
--- initial
+++ final
@@ -1,34 +1,33 @@
static void VmbusOnMsgDPC(struct hv_driver *drv) {
int cpu = smp_processor_id();
void *page_addr = gHvContext.synICMessagePage[cpu];
struct hv_message *msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
struct hv_message *copied;
while (1) {
if (msg->Header.MessageType == HvMessageTypeNone) {
/* no msg */
break;
} else {
- copied = kmalloc(sizeof(*copied), GFP_ATOMIC);
+ copied = kmemdup(msg, sizeof(*copied), GFP_ATOMIC);
if (copied == NULL) continue;
- memcpy(copied, msg, sizeof(*copied));
osd_schedule_callback(gVmbusConnection.WorkQueue, VmbusOnChannelMessage, (void *)copied);
}
msg->Header.MessageType = HvMessageTypeNone;
/*
* Make sure the write to MessageType (ie set to
* HvMessageTypeNone) happens before we read the
* MessagePending and EOMing. Otherwise, the EOMing
* will not deliver any more messages since there is
* no empty slot
*/
mb();
if (msg->Header.MessageFlags.MessagePending) {
/*
* This will cause message queue rescan to
* possibly deliver another msg from the
* hypervisor
*/
wrmsrl(HV_X64_MSR_EOM, 0);
}
}
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 697 |
--- initial
+++ final
@@ -1,39 +1,38 @@
static __init acpi_status parse_wdg(acpi_handle handle) {
struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
union acpi_object *obj;
struct guid_block *gblock;
struct wmi_block *wblock;
char guid_string[37];
acpi_status status;
u32 i, total;
status = acpi_evaluate_object(handle, "_WDG", NULL, &out);
if (ACPI_FAILURE(status)) return status;
obj = (union acpi_object *)out.pointer;
if (obj->type != ACPI_TYPE_BUFFER) return AE_ERROR;
total = obj->buffer.length / sizeof(struct guid_block);
- gblock = kzalloc(obj->buffer.length, GFP_KERNEL);
+ gblock = kmemdup(obj->buffer.pointer, obj->buffer.length, GFP_KERNEL);
if (!gblock) return AE_NO_MEMORY;
- memcpy(gblock, obj->buffer.pointer, obj->buffer.length);
for (i = 0; i < total; i++) {
/*
Some WMI devices, like those for nVidia hooks, have a
duplicate GUID. It's not clear what we should do in this
case yet, so for now, we'll just ignore the duplicate.
Anyone who wants to add support for that device can come
up with a better workaround for the mess then.
*/
if (guid_already_parsed(gblock[i].guid) == true) {
wmi_gtoa(gblock[i].guid, guid_string);
printk(KERN_INFO PREFIX "Skipping duplicate GUID %s\n", guid_string);
continue;
}
wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL);
if (!wblock) return AE_NO_MEMORY;
wblock->gblock = gblock[i];
wblock->handle = handle;
list_add_tail(&wblock->list, &wmi_blocks.list);
}
kfree(out.pointer);
kfree(gblock);
return status;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 698 |
--- initial
+++ final
@@ -1,17 +1,16 @@
int rdma_set_ib_paths(struct rdma_cm_id *id, struct ib_sa_path_rec *path_rec, int num_paths) {
struct rdma_id_private *id_priv;
int ret;
id_priv = container_of(id, struct rdma_id_private, id);
if (!cma_comp_exch(id_priv, CMA_ADDR_RESOLVED, CMA_ROUTE_RESOLVED)) return -EINVAL;
- id->route.path_rec = kmalloc(sizeof *path_rec * num_paths, GFP_KERNEL);
+ id->route.path_rec = kmemdup(path_rec, sizeof *path_rec * num_paths, GFP_KERNEL);
if (!id->route.path_rec) {
ret = -ENOMEM;
goto err;
}
- memcpy(id->route.path_rec, path_rec, sizeof *path_rec * num_paths);
id->route.num_paths = num_paths;
return 0;
err:
cma_comp_exch(id_priv, CMA_ROUTE_RESOLVED, CMA_ADDR_RESOLVED);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 699 |
--- initial
+++ final
@@ -1,147 +1,145 @@
struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device, u8 port_num, enum ib_qp_type qp_type, struct ib_mad_reg_req *mad_reg_req, u8 rmpp_version, ib_mad_send_handler send_handler, ib_mad_recv_handler recv_handler, void *context) {
struct ib_mad_port_private *port_priv;
struct ib_mad_agent *ret = ERR_PTR(-EINVAL);
struct ib_mad_agent_private *mad_agent_priv;
struct ib_mad_reg_req *reg_req = NULL;
struct ib_mad_mgmt_class_table *class;
struct ib_mad_mgmt_vendor_class_table *vendor;
struct ib_mad_mgmt_vendor_class *vendor_class;
struct ib_mad_mgmt_method_table *method;
int ret2, qpn;
unsigned long flags;
u8 mgmt_class, vclass;
/* Validate parameters */
qpn = get_spl_qp_index(qp_type);
if (qpn == -1) goto error1;
if (rmpp_version && rmpp_version != IB_MGMT_RMPP_VERSION) goto error1;
/* Validate MAD registration request if supplied */
if (mad_reg_req) {
if (mad_reg_req->mgmt_class_version >= MAX_MGMT_VERSION) goto error1;
if (!recv_handler) goto error1;
if (mad_reg_req->mgmt_class >= MAX_MGMT_CLASS) {
/*
* IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE is the only
* one in this range currently allowed
*/
if (mad_reg_req->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) goto error1;
} else if (mad_reg_req->mgmt_class == 0) {
/*
* Class 0 is reserved in IBA and is used for
* aliasing of IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
*/
goto error1;
} else if (is_vendor_class(mad_reg_req->mgmt_class)) {
/*
* If class is in "new" vendor range,
* ensure supplied OUI is not zero
*/
if (!is_vendor_oui(mad_reg_req->oui)) goto error1;
}
/* Make sure class supplied is consistent with RMPP */
if (!ib_is_mad_class_rmpp(mad_reg_req->mgmt_class)) {
if (rmpp_version) goto error1;
}
/* Make sure class supplied is consistent with QP type */
if (qp_type == IB_QPT_SMI) {
if ((mad_reg_req->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED) && (mad_reg_req->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) goto error1;
} else {
if ((mad_reg_req->mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED) || (mad_reg_req->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)) goto error1;
}
} else {
/* No registration request supplied */
if (!send_handler) goto error1;
}
/* Validate device and port */
port_priv = ib_get_mad_port(device, port_num);
if (!port_priv) {
ret = ERR_PTR(-ENODEV);
goto error1;
}
/* Allocate structures */
mad_agent_priv = kzalloc(sizeof *mad_agent_priv, GFP_KERNEL);
if (!mad_agent_priv) {
ret = ERR_PTR(-ENOMEM);
goto error1;
}
mad_agent_priv->agent.mr = ib_get_dma_mr(port_priv->qp_info[qpn].qp->pd, IB_ACCESS_LOCAL_WRITE);
if (IS_ERR(mad_agent_priv->agent.mr)) {
ret = ERR_PTR(-ENOMEM);
goto error2;
}
if (mad_reg_req) {
- reg_req = kmalloc(sizeof *reg_req, GFP_KERNEL);
+ reg_req = kmemdup(mad_reg_req, sizeof *reg_req, GFP_KERNEL);
if (!reg_req) {
ret = ERR_PTR(-ENOMEM);
goto error3;
}
- /* Make a copy of the MAD registration request */
- memcpy(reg_req, mad_reg_req, sizeof *reg_req);
}
/* Now, fill in the various structures */
mad_agent_priv->qp_info = &port_priv->qp_info[qpn];
mad_agent_priv->reg_req = reg_req;
mad_agent_priv->agent.rmpp_version = rmpp_version;
mad_agent_priv->agent.device = device;
mad_agent_priv->agent.recv_handler = recv_handler;
mad_agent_priv->agent.send_handler = send_handler;
mad_agent_priv->agent.context = context;
mad_agent_priv->agent.qp = port_priv->qp_info[qpn].qp;
mad_agent_priv->agent.port_num = port_num;
spin_lock_init(&mad_agent_priv->lock);
INIT_LIST_HEAD(&mad_agent_priv->send_list);
INIT_LIST_HEAD(&mad_agent_priv->wait_list);
INIT_LIST_HEAD(&mad_agent_priv->done_list);
INIT_LIST_HEAD(&mad_agent_priv->rmpp_list);
INIT_DELAYED_WORK(&mad_agent_priv->timed_work, timeout_sends);
INIT_LIST_HEAD(&mad_agent_priv->local_list);
INIT_WORK(&mad_agent_priv->local_work, local_completions);
atomic_set(&mad_agent_priv->refcount, 1);
init_completion(&mad_agent_priv->comp);
spin_lock_irqsave(&port_priv->reg_lock, flags);
mad_agent_priv->agent.hi_tid = ++ib_mad_client_id;
/*
* Make sure MAD registration (if supplied)
* is non overlapping with any existing ones
*/
if (mad_reg_req) {
mgmt_class = convert_mgmt_class(mad_reg_req->mgmt_class);
if (!is_vendor_class(mgmt_class)) {
class = port_priv->version[mad_reg_req->mgmt_class_version].class;
if (class) {
method = class->method_table[mgmt_class];
if (method) {
if (method_in_use(&method, mad_reg_req)) goto error4;
}
}
ret2 = add_nonoui_reg_req(mad_reg_req, mad_agent_priv, mgmt_class);
} else {
/* "New" vendor class range */
vendor = port_priv->version[mad_reg_req->mgmt_class_version].vendor;
if (vendor) {
vclass = vendor_class_index(mgmt_class);
vendor_class = vendor->vendor_class[vclass];
if (vendor_class) {
if (is_vendor_method_in_use(vendor_class, mad_reg_req)) goto error4;
}
}
ret2 = add_oui_reg_req(mad_reg_req, mad_agent_priv);
}
if (ret2) {
ret = ERR_PTR(ret2);
goto error4;
}
}
/* Add mad agent into port's agent list */
list_add_tail(&mad_agent_priv->agent_list, &port_priv->agent_list);
spin_unlock_irqrestore(&port_priv->reg_lock, flags);
return &mad_agent_priv->agent;
error4:
spin_unlock_irqrestore(&port_priv->reg_lock, flags);
kfree(reg_req);
error3:
ib_dereg_mr(mad_agent_priv->agent.mr);
error2:
kfree(mad_agent_priv);
error1:
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 700 |
--- initial
+++ final
@@ -1,130 +1,129 @@
int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len) {
struct p54_common *priv = dev->priv;
struct eeprom_pda_wrap *wrap;
struct pda_entry *entry;
unsigned int data_len, entry_len;
void *tmp;
int err;
u8 *end = (u8 *)eeprom + len;
u16 synth = 0;
wrap = (struct eeprom_pda_wrap *)eeprom;
entry = (void *)wrap->data + le16_to_cpu(wrap->len);
/* verify that at least the entry length/code fits */
while ((u8 *)entry <= end - sizeof(*entry)) {
entry_len = le16_to_cpu(entry->len);
data_len = ((entry_len - 1) << 1);
/* abort if entry exceeds whole structure */
if ((u8 *)entry + sizeof(*entry) + data_len > end) break;
switch (le16_to_cpu(entry->code)) {
case PDR_MAC_ADDRESS:
if (data_len != ETH_ALEN) break;
SET_IEEE80211_PERM_ADDR(dev, entry->data);
break;
case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS:
if (priv->output_limit) break;
err = p54_convert_output_limits(dev, entry->data, data_len);
if (err) goto err;
break;
case PDR_PRISM_PA_CAL_CURVE_DATA: {
struct pda_pa_curve_data *curve_data = (struct pda_pa_curve_data *)entry->data;
if (data_len < sizeof(*curve_data)) {
err = -EINVAL;
goto err;
}
switch (curve_data->cal_method_rev) {
case 0: err = p54_convert_rev0(dev, curve_data); break;
case 1: err = p54_convert_rev1(dev, curve_data); break;
default:
printk(KERN_ERR "%s: unknown curve data "
"revision %d\n",
wiphy_name(dev->wiphy), curve_data->cal_method_rev);
err = -ENODEV;
break;
}
if (err) goto err;
} break;
case PDR_PRISM_ZIF_TX_IQ_CALIBRATION:
- priv->iq_autocal = kmalloc(data_len, GFP_KERNEL);
+ priv->iq_autocal = kmemdup(entry->data, data_len, GFP_KERNEL);
if (!priv->iq_autocal) {
err = -ENOMEM;
goto err;
}
- memcpy(priv->iq_autocal, entry->data, data_len);
priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry);
break;
case PDR_DEFAULT_COUNTRY: p54_parse_default_country(dev, entry->data, data_len); break;
case PDR_INTERFACE_LIST:
tmp = entry->data;
while ((u8 *)tmp < entry->data + data_len) {
struct exp_if *exp_if = tmp;
if (exp_if->if_id == cpu_to_le16(IF_ID_ISL39000)) synth = le16_to_cpu(exp_if->variant);
tmp += sizeof(*exp_if);
}
break;
case PDR_HARDWARE_PLATFORM_COMPONENT_ID:
if (data_len < 2) break;
priv->version = *(u8 *)(entry->data + 1);
break;
case PDR_RSSI_LINEAR_APPROXIMATION:
case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND:
case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED: p54_parse_rssical(dev, entry->data, data_len, le16_to_cpu(entry->code)); break;
case PDR_RSSI_LINEAR_APPROXIMATION_CUSTOM: {
__le16 *src = (void *)entry->data;
s16 *dst = (void *)&priv->rssical_db;
int i;
if (data_len != sizeof(priv->rssical_db)) {
err = -EINVAL;
goto err;
}
for (i = 0; i < sizeof(priv->rssical_db) / sizeof(*src); i++)
*(dst++) = (s16)le16_to_cpu(*(src++));
} break;
case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS_CUSTOM: {
struct pda_custom_wrapper *pda = (void *)entry->data;
if (priv->output_limit || data_len < sizeof(*pda)) break;
priv->output_limit = p54_convert_db(pda, data_len);
} break;
case PDR_PRISM_PA_CAL_CURVE_DATA_CUSTOM: {
struct pda_custom_wrapper *pda = (void *)entry->data;
if (priv->curve_data || data_len < sizeof(*pda)) break;
priv->curve_data = p54_convert_db(pda, data_len);
} break;
case PDR_END:
/* make it overrun */
entry_len = len;
break;
default: break;
}
entry = (void *)entry + (entry_len + 1) * 2;
}
if (!synth || !priv->iq_autocal || !priv->output_limit || !priv->curve_data) {
printk(KERN_ERR "%s: not all required entries found in eeprom!\n", wiphy_name(dev->wiphy));
err = -EINVAL;
goto err;
}
err = p54_generate_channel_lists(dev);
if (err) goto err;
priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK;
if (priv->rxhw == PDR_SYNTH_FRONTEND_XBOW) p54_init_xbow_synth(priv);
if (!(synth & PDR_SYNTH_24_GHZ_DISABLED)) dev->wiphy->bands[IEEE80211_BAND_2GHZ] = priv->band_table[IEEE80211_BAND_2GHZ];
if (!(synth & PDR_SYNTH_5_GHZ_DISABLED)) dev->wiphy->bands[IEEE80211_BAND_5GHZ] = priv->band_table[IEEE80211_BAND_5GHZ];
if ((synth & PDR_SYNTH_RX_DIV_MASK) == PDR_SYNTH_RX_DIV_SUPPORTED) priv->rx_diversity_mask = 3;
if ((synth & PDR_SYNTH_TX_DIV_MASK) == PDR_SYNTH_TX_DIV_SUPPORTED) priv->tx_diversity_mask = 3;
if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
u8 perm_addr[ETH_ALEN];
printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n", wiphy_name(dev->wiphy));
random_ether_addr(perm_addr);
SET_IEEE80211_PERM_ADDR(dev, perm_addr);
}
printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n", wiphy_name(dev->wiphy), dev->wiphy->perm_addr, priv->version, p54_rf_chips[priv->rxhw]);
return 0;
err:
kfree(priv->iq_autocal);
kfree(priv->output_limit);
kfree(priv->curve_data);
priv->iq_autocal = NULL;
priv->output_limit = NULL;
priv->curve_data = NULL;
printk(KERN_ERR "%s: eeprom parse failed!\n", wiphy_name(dev->wiphy));
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 701 |
--- initial
+++ final
@@ -1,16 +1,15 @@
static int p54u_firmware_reset_3887(struct ieee80211_hw *dev) {
struct p54u_priv *priv = dev->priv;
u8 *buf;
int ret;
- buf = kmalloc(4, GFP_KERNEL);
+ buf = kmemdup(p54u_romboot_3887, 4, GFP_KERNEL);
if (!buf) return -ENOMEM;
- memcpy(buf, p54u_romboot_3887, 4);
ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 4);
kfree(buf);
if (ret)
dev_err(&priv->udev->dev,
"(p54usb) unable to jump to "
"boot ROM (%d)!\n",
ret);
return ret;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 702 |
--- initial
+++ final
@@ -1,57 +1,56 @@
static int concat_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen) {
struct mtd_concat *concat = CONCAT(mtd);
struct kvec *vecs_copy;
unsigned long entry_low, entry_high;
size_t total_len = 0;
int i;
int err = -EINVAL;
if (!(mtd->flags & MTD_WRITEABLE)) return -EROFS;
*retlen = 0;
/* Calculate total length of data */
for (i = 0; i < count; i++)
total_len += vecs[i].iov_len;
/* Do not allow write past end of device */
if ((to + total_len) > mtd->size) return -EINVAL;
/* Check alignment */
if (mtd->writesize > 1) {
uint64_t __to = to;
if (do_div(__to, mtd->writesize) || (total_len % mtd->writesize)) return -EINVAL;
}
/* make a copy of vecs */
- vecs_copy = kmalloc(sizeof(struct kvec) * count, GFP_KERNEL);
+ vecs_copy = kmemdup(vecs, sizeof(struct kvec) * count, GFP_KERNEL);
if (!vecs_copy) return -ENOMEM;
- memcpy(vecs_copy, vecs, sizeof(struct kvec) * count);
entry_low = 0;
for (i = 0; i < concat->num_subdev; i++) {
struct mtd_info *subdev = concat->subdev[i];
size_t size, wsize, retsize, old_iov_len;
if (to >= subdev->size) {
to -= subdev->size;
continue;
}
size = min_t(uint64_t, total_len, subdev->size - to);
wsize = size; /* store for future use */
entry_high = entry_low;
while (entry_high < count) {
if (size <= vecs_copy[entry_high].iov_len) break;
size -= vecs_copy[entry_high++].iov_len;
}
old_iov_len = vecs_copy[entry_high].iov_len;
vecs_copy[entry_high].iov_len = size;
if (!(subdev->flags & MTD_WRITEABLE))
err = -EROFS;
else
err = subdev->writev(subdev, &vecs_copy[entry_low], entry_high - entry_low + 1, to, &retsize);
vecs_copy[entry_high].iov_len = old_iov_len - size;
vecs_copy[entry_high].iov_base += size;
entry_low = entry_high;
if (err) break;
*retlen += retsize;
total_len -= wsize;
if (total_len == 0) break;
err = -EINVAL;
to = 0;
}
kfree(vecs_copy);
return err;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 703 |
--- initial
+++ final
@@ -1,29 +1,28 @@
static int orinoco_ioctl_set_genie(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) {
struct orinoco_private *priv = ndev_priv(dev);
u8 *buf;
unsigned long flags;
/* cut off at IEEE80211_MAX_DATA_LEN */
if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) || (wrqu->data.length && (extra == NULL))) return -EINVAL;
if (wrqu->data.length) {
- buf = kmalloc(wrqu->data.length, GFP_KERNEL);
+ buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
if (buf == NULL) return -ENOMEM;
- memcpy(buf, extra, wrqu->data.length);
} else
buf = NULL;
if (orinoco_lock(priv, &flags) != 0) {
kfree(buf);
return -EBUSY;
}
kfree(priv->wpa_ie);
priv->wpa_ie = buf;
priv->wpa_ie_len = wrqu->data.length;
if (priv->wpa_ie) {
/* Looks like wl_lkm wants to check the auth alg, and
* somehow pass it to the firmware.
* Instead it just calls the key mgmt rid
* - we do this in set auth.
*/
}
orinoco_unlock(priv, &flags);
return 0;
}<sep>@@
expression from,to,size,flag;
statement S;
@@
- to = \(kmalloc\|kzalloc\)(size,flag);
+ to = kmemdup(from,size,flag);
if (to==NULL || ...) S
- memcpy(to, from, size);
<|end_of_text|> | 704 |