aboutsummaryrefslogtreecommitdiffstats
path: root/net/rfkill
diff options
context:
space:
mode:
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>2013-10-16 06:53:39 -0400
committerJohannes Berg <johannes.berg@intel.com>2013-10-28 10:05:23 -0400
commit5e7ca3937fbeaedd7383058ea2bd9af1089ef81a (patch)
tree1584bee9c3c62d381afef39ff99435b524222e3d /net/rfkill
parentee26eaefe3fc22fdf60b6bed986a55dafda07770 (diff)
net: rfkill: gpio: convert to resource managed allocation
And remove now unneeded resource freeing. Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Acked-by: Rhyland Klein <rklein@nvidia.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/rfkill')
-rw-r--r--net/rfkill/rfkill-gpio.c75
1 files changed, 20 insertions, 55 deletions
diff --git a/net/rfkill/rfkill-gpio.c b/net/rfkill/rfkill-gpio.c
index fb076cd6f808..070580619e3d 100644
--- a/net/rfkill/rfkill-gpio.c
+++ b/net/rfkill/rfkill-gpio.c
@@ -97,7 +97,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
97 return -EINVAL; 97 return -EINVAL;
98 } 98 }
99 99
100 rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL); 100 rfkill = devm_kzalloc(&pdev->dev, sizeof(*rfkill), GFP_KERNEL);
101 if (!rfkill) 101 if (!rfkill)
102 return -ENOMEM; 102 return -ENOMEM;
103 103
@@ -105,89 +105,65 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
105 ret = pdata->gpio_runtime_setup(pdev); 105 ret = pdata->gpio_runtime_setup(pdev);
106 if (ret) { 106 if (ret) {
107 pr_warn("%s: can't set up gpio\n", __func__); 107 pr_warn("%s: can't set up gpio\n", __func__);
108 goto fail_alloc; 108 return ret;
109 } 109 }
110 } 110 }
111 111
112 rfkill->pdata = pdata; 112 rfkill->pdata = pdata;
113 113
114 len = strlen(pdata->name); 114 len = strlen(pdata->name);
115 rfkill->reset_name = kzalloc(len + 7, GFP_KERNEL); 115 rfkill->reset_name = devm_kzalloc(&pdev->dev, len + 7, GFP_KERNEL);
116 if (!rfkill->reset_name) { 116 if (!rfkill->reset_name)
117 ret = -ENOMEM; 117 return -ENOMEM;
118 goto fail_alloc;
119 }
120 118
121 rfkill->shutdown_name = kzalloc(len + 10, GFP_KERNEL); 119 rfkill->shutdown_name = devm_kzalloc(&pdev->dev, len + 10, GFP_KERNEL);
122 if (!rfkill->shutdown_name) { 120 if (!rfkill->shutdown_name)
123 ret = -ENOMEM; 121 return -ENOMEM;
124 goto fail_reset_name;
125 }
126 122
127 snprintf(rfkill->reset_name, len + 6 , "%s_reset", pdata->name); 123 snprintf(rfkill->reset_name, len + 6 , "%s_reset", pdata->name);
128 snprintf(rfkill->shutdown_name, len + 9, "%s_shutdown", pdata->name); 124 snprintf(rfkill->shutdown_name, len + 9, "%s_shutdown", pdata->name);
129 125
130 if (pdata->power_clk_name) { 126 if (pdata->power_clk_name) {
131 rfkill->pwr_clk = clk_get(&pdev->dev, pdata->power_clk_name); 127 rfkill->pwr_clk = devm_clk_get(&pdev->dev,
128 pdata->power_clk_name);
132 if (IS_ERR(rfkill->pwr_clk)) { 129 if (IS_ERR(rfkill->pwr_clk)) {
133 pr_warn("%s: can't find pwr_clk.\n", __func__); 130 pr_warn("%s: can't find pwr_clk.\n", __func__);
134 ret = PTR_ERR(rfkill->pwr_clk); 131 return PTR_ERR(rfkill->pwr_clk);
135 goto fail_shutdown_name;
136 } 132 }
137 } 133 }
138 134
139 if (gpio_is_valid(pdata->reset_gpio)) { 135 if (gpio_is_valid(pdata->reset_gpio)) {
140 ret = gpio_request(pdata->reset_gpio, rfkill->reset_name); 136 ret = devm_gpio_request(&pdev->dev, pdata->reset_gpio,
137 rfkill->reset_name);
141 if (ret) { 138 if (ret) {
142 pr_warn("%s: failed to get reset gpio.\n", __func__); 139 pr_warn("%s: failed to get reset gpio.\n", __func__);
143 goto fail_clock; 140 return ret;
144 } 141 }
145 } 142 }
146 143
147 if (gpio_is_valid(pdata->shutdown_gpio)) { 144 if (gpio_is_valid(pdata->shutdown_gpio)) {
148 ret = gpio_request(pdata->shutdown_gpio, rfkill->shutdown_name); 145 ret = devm_gpio_request(&pdev->dev, pdata->shutdown_gpio,
146 rfkill->shutdown_name);
149 if (ret) { 147 if (ret) {
150 pr_warn("%s: failed to get shutdown gpio.\n", __func__); 148 pr_warn("%s: failed to get shutdown gpio.\n", __func__);
151 goto fail_reset; 149 return ret;
152 } 150 }
153 } 151 }
154 152
155 rfkill->rfkill_dev = rfkill_alloc(pdata->name, &pdev->dev, pdata->type, 153 rfkill->rfkill_dev = rfkill_alloc(pdata->name, &pdev->dev, pdata->type,
156 &rfkill_gpio_ops, rfkill); 154 &rfkill_gpio_ops, rfkill);
157 if (!rfkill->rfkill_dev) { 155 if (!rfkill->rfkill_dev)
158 ret = -ENOMEM; 156 return -ENOMEM;
159 goto fail_shutdown;
160 }
161 157
162 ret = rfkill_register(rfkill->rfkill_dev); 158 ret = rfkill_register(rfkill->rfkill_dev);
163 if (ret < 0) 159 if (ret < 0)
164 goto fail_rfkill; 160 return ret;
165 161
166 platform_set_drvdata(pdev, rfkill); 162 platform_set_drvdata(pdev, rfkill);
167 163
168 dev_info(&pdev->dev, "%s device registered.\n", pdata->name); 164 dev_info(&pdev->dev, "%s device registered.\n", pdata->name);
169 165
170 return 0; 166 return 0;
171
172fail_rfkill:
173 rfkill_destroy(rfkill->rfkill_dev);
174fail_shutdown:
175 if (gpio_is_valid(pdata->shutdown_gpio))
176 gpio_free(pdata->shutdown_gpio);
177fail_reset:
178 if (gpio_is_valid(pdata->reset_gpio))
179 gpio_free(pdata->reset_gpio);
180fail_clock:
181 if (rfkill->pwr_clk)
182 clk_put(rfkill->pwr_clk);
183fail_shutdown_name:
184 kfree(rfkill->shutdown_name);
185fail_reset_name:
186 kfree(rfkill->reset_name);
187fail_alloc:
188 kfree(rfkill);
189
190 return ret;
191} 167}
192 168
193static int rfkill_gpio_remove(struct platform_device *pdev) 169static int rfkill_gpio_remove(struct platform_device *pdev)
@@ -199,17 +175,6 @@ static int rfkill_gpio_remove(struct platform_device *pdev)
199 pdata->gpio_runtime_close(pdev); 175 pdata->gpio_runtime_close(pdev);
200 rfkill_unregister(rfkill->rfkill_dev); 176 rfkill_unregister(rfkill->rfkill_dev);
201 rfkill_destroy(rfkill->rfkill_dev); 177 rfkill_destroy(rfkill->rfkill_dev);
202 if (gpio_is_valid(rfkill->pdata->shutdown_gpio))
203 gpio_free(rfkill->pdata->shutdown_gpio);
204 if (gpio_is_valid(rfkill->pdata->reset_gpio))
205 gpio_free(rfkill->pdata->reset_gpio);
206 if (rfkill->pwr_clk && PWR_CLK_ENABLED(rfkill))
207 clk_disable(rfkill->pwr_clk);
208 if (rfkill->pwr_clk)
209 clk_put(rfkill->pwr_clk);
210 kfree(rfkill->shutdown_name);
211 kfree(rfkill->reset_name);
212 kfree(rfkill);
213 178
214 return 0; 179 return 0;
215} 180}