diff options
| author | Chanwoo Choi <cw00.choi@samsung.com> | 2014-04-21 07:49:30 -0400 |
|---|---|---|
| committer | Chanwoo Choi <cw00.choi@samsung.com> | 2014-04-28 20:51:22 -0400 |
| commit | 1876fd9af59904078a73bdd4283c3924fd6cf18e (patch) | |
| tree | 75ddeb167d9305462d137da048eba62f07302742 | |
| parent | ef70a214b558184867e5943cf943a03293250ea7 (diff) | |
extcon: adc-jack: Use devm_extcon_dev_allocate for extcon_dev
This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Reviewed-by: Felipe Balbi <balbi@ti.com>
| -rw-r--r-- | drivers/extcon/extcon-adc-jack.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index 549d8207aacf..e18f95be3733 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c | |||
| @@ -39,7 +39,7 @@ | |||
| 39 | * @chan: iio channel being queried. | 39 | * @chan: iio channel being queried. |
| 40 | */ | 40 | */ |
| 41 | struct adc_jack_data { | 41 | struct adc_jack_data { |
| 42 | struct extcon_dev edev; | 42 | struct extcon_dev *edev; |
| 43 | 43 | ||
| 44 | const char **cable_names; | 44 | const char **cable_names; |
| 45 | int num_cables; | 45 | int num_cables; |
| @@ -64,7 +64,7 @@ static void adc_jack_handler(struct work_struct *work) | |||
| 64 | 64 | ||
| 65 | ret = iio_read_channel_raw(data->chan, &adc_val); | 65 | ret = iio_read_channel_raw(data->chan, &adc_val); |
| 66 | if (ret < 0) { | 66 | if (ret < 0) { |
| 67 | dev_err(&data->edev.dev, "read channel() error: %d\n", ret); | 67 | dev_err(&data->edev->dev, "read channel() error: %d\n", ret); |
| 68 | return; | 68 | return; |
| 69 | } | 69 | } |
| 70 | 70 | ||
| @@ -80,7 +80,7 @@ static void adc_jack_handler(struct work_struct *work) | |||
| 80 | } | 80 | } |
| 81 | /* if no def has met, it means state = 0 (no cables attached) */ | 81 | /* if no def has met, it means state = 0 (no cables attached) */ |
| 82 | 82 | ||
| 83 | extcon_set_state(&data->edev, state); | 83 | extcon_set_state(data->edev, state); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | static irqreturn_t adc_jack_irq_thread(int irq, void *_data) | 86 | static irqreturn_t adc_jack_irq_thread(int irq, void *_data) |
| @@ -102,18 +102,21 @@ static int adc_jack_probe(struct platform_device *pdev) | |||
| 102 | if (!data) | 102 | if (!data) |
| 103 | return -ENOMEM; | 103 | return -ENOMEM; |
| 104 | 104 | ||
| 105 | data->edev.name = pdata->name; | ||
| 106 | |||
| 107 | if (!pdata->cable_names) { | 105 | if (!pdata->cable_names) { |
| 108 | dev_err(&pdev->dev, "error: cable_names not defined.\n"); | 106 | dev_err(&pdev->dev, "error: cable_names not defined.\n"); |
| 109 | return -EINVAL; | 107 | return -EINVAL; |
| 110 | } | 108 | } |
| 111 | 109 | ||
| 112 | data->edev.dev.parent = &pdev->dev; | 110 | data->edev = devm_extcon_dev_allocate(&pdev->dev, pdata->cable_names); |
| 113 | data->edev.supported_cable = pdata->cable_names; | 111 | if (IS_ERR(data->edev)) { |
| 112 | dev_err(&pdev->dev, "failed to allocate extcon device\n"); | ||
| 113 | return -ENOMEM; | ||
| 114 | } | ||
| 115 | data->edev->dev.parent = &pdev->dev; | ||
| 116 | data->edev->name = pdata->name; | ||
| 114 | 117 | ||
| 115 | /* Check the length of array and set num_cables */ | 118 | /* Check the length of array and set num_cables */ |
| 116 | for (i = 0; data->edev.supported_cable[i]; i++) | 119 | for (i = 0; data->edev->supported_cable[i]; i++) |
| 117 | ; | 120 | ; |
| 118 | if (i == 0 || i > SUPPORTED_CABLE_MAX) { | 121 | if (i == 0 || i > SUPPORTED_CABLE_MAX) { |
| 119 | dev_err(&pdev->dev, "error: pdata->cable_names size = %d\n", | 122 | dev_err(&pdev->dev, "error: pdata->cable_names size = %d\n", |
| @@ -144,7 +147,7 @@ static int adc_jack_probe(struct platform_device *pdev) | |||
| 144 | 147 | ||
| 145 | platform_set_drvdata(pdev, data); | 148 | platform_set_drvdata(pdev, data); |
| 146 | 149 | ||
| 147 | err = devm_extcon_dev_register(&pdev->dev, &data->edev); | 150 | err = devm_extcon_dev_register(&pdev->dev, data->edev); |
| 148 | if (err) | 151 | if (err) |
| 149 | return err; | 152 | return err; |
| 150 | 153 | ||
