diff options
author | Julia Lawall <Julia.Lawall@lip6.fr> | 2012-12-06 18:15:24 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-01-16 02:38:43 -0500 |
commit | e5279ff6c9f5e950feac6e6f48621db912324c07 (patch) | |
tree | 9c09cf2efa2269b31c3a4ae14f74dd47391a727a /drivers/w1 | |
parent | eea2172e6915a92cab1d3a79a4961e14a3c388ff (diff) |
drivers/w1/masters/mxc_w1.c: use devm_ functions
The various devm_ functions allocate memory that is released when a driver
detaches. This patch uses these functions for data that is allocated in
the probe function of a platform device and is only freed in the remove
function.
At the same time, this fixes two faults. First, mdev, the result of
kzalloc, was never freed. Second, on failure of ioremap, 0 was returned.
This has been replaced by -EBUSY, which was the failure value for the call
to request_mem_region, with which the call to ioremap has been combined.
The warning message on failure of ioremap is dropped, because
devm_request_and_ioremap already gives such messages on failure.
Finally, the initial call to platform_get_resource is moved closer to the
call to devm_request_and_ioremap, which takes care of checking whether its
result is NULL, implying that a test on the result of this call to
platform_get_resource is not needed.
Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/masters/mxc_w1.c | 49 |
1 files changed, 10 insertions, 39 deletions
diff --git a/drivers/w1/masters/mxc_w1.c b/drivers/w1/masters/mxc_w1.c index 708a25fc9961..372c8c0d54a0 100644 --- a/drivers/w1/masters/mxc_w1.c +++ b/drivers/w1/masters/mxc_w1.c | |||
@@ -109,34 +109,21 @@ static int mxc_w1_probe(struct platform_device *pdev) | |||
109 | struct resource *res; | 109 | struct resource *res; |
110 | int err = 0; | 110 | int err = 0; |
111 | 111 | ||
112 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 112 | mdev = devm_kzalloc(&pdev->dev, sizeof(struct mxc_w1_device), |
113 | if (!res) | 113 | GFP_KERNEL); |
114 | return -ENODEV; | ||
115 | |||
116 | mdev = kzalloc(sizeof(struct mxc_w1_device), GFP_KERNEL); | ||
117 | if (!mdev) | 114 | if (!mdev) |
118 | return -ENOMEM; | 115 | return -ENOMEM; |
119 | 116 | ||
120 | mdev->clk = clk_get(&pdev->dev, NULL); | 117 | mdev->clk = devm_clk_get(&pdev->dev, NULL); |
121 | if (IS_ERR(mdev->clk)) { | 118 | if (IS_ERR(mdev->clk)) |
122 | err = PTR_ERR(mdev->clk); | 119 | return PTR_ERR(mdev->clk); |
123 | goto failed_clk; | ||
124 | } | ||
125 | 120 | ||
126 | mdev->clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1; | 121 | mdev->clkdiv = (clk_get_rate(mdev->clk) / 1000000) - 1; |
127 | 122 | ||
128 | res = request_mem_region(res->start, resource_size(res), | 123 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
129 | "mxc_w1"); | 124 | mdev->regs = devm_request_and_ioremap(&pdev->dev, res); |
130 | if (!res) { | 125 | if (!mdev->regs) |
131 | err = -EBUSY; | 126 | return -EBUSY; |
132 | goto failed_req; | ||
133 | } | ||
134 | |||
135 | mdev->regs = ioremap(res->start, resource_size(res)); | ||
136 | if (!mdev->regs) { | ||
137 | dev_err(&pdev->dev, "Cannot map mxc_w1 registers\n"); | ||
138 | goto failed_ioremap; | ||
139 | } | ||
140 | 127 | ||
141 | clk_prepare_enable(mdev->clk); | 128 | clk_prepare_enable(mdev->clk); |
142 | __raw_writeb(mdev->clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER); | 129 | __raw_writeb(mdev->clkdiv, mdev->regs + MXC_W1_TIME_DIVIDER); |
@@ -148,20 +135,10 @@ static int mxc_w1_probe(struct platform_device *pdev) | |||
148 | err = w1_add_master_device(&mdev->bus_master); | 135 | err = w1_add_master_device(&mdev->bus_master); |
149 | 136 | ||
150 | if (err) | 137 | if (err) |
151 | goto failed_add; | 138 | return err; |
152 | 139 | ||
153 | platform_set_drvdata(pdev, mdev); | 140 | platform_set_drvdata(pdev, mdev); |
154 | return 0; | 141 | return 0; |
155 | |||
156 | failed_add: | ||
157 | iounmap(mdev->regs); | ||
158 | failed_ioremap: | ||
159 | release_mem_region(res->start, resource_size(res)); | ||
160 | failed_req: | ||
161 | clk_put(mdev->clk); | ||
162 | failed_clk: | ||
163 | kfree(mdev); | ||
164 | return err; | ||
165 | } | 142 | } |
166 | 143 | ||
167 | /* | 144 | /* |
@@ -170,16 +147,10 @@ failed_clk: | |||
170 | static int mxc_w1_remove(struct platform_device *pdev) | 147 | static int mxc_w1_remove(struct platform_device *pdev) |
171 | { | 148 | { |
172 | struct mxc_w1_device *mdev = platform_get_drvdata(pdev); | 149 | struct mxc_w1_device *mdev = platform_get_drvdata(pdev); |
173 | struct resource *res; | ||
174 | |||
175 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
176 | 150 | ||
177 | w1_remove_master_device(&mdev->bus_master); | 151 | w1_remove_master_device(&mdev->bus_master); |
178 | 152 | ||
179 | iounmap(mdev->regs); | ||
180 | release_mem_region(res->start, resource_size(res)); | ||
181 | clk_disable_unprepare(mdev->clk); | 153 | clk_disable_unprepare(mdev->clk); |
182 | clk_put(mdev->clk); | ||
183 | 154 | ||
184 | platform_set_drvdata(pdev, NULL); | 155 | platform_set_drvdata(pdev, NULL); |
185 | 156 | ||