This change moves the simple allocations to their device-managed
equivalents.
This cleans up some error/exit paths.
Signed-off-by: Alexandru Ardelean <[email protected]>
---
drivers/uio/uio_pruss.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)
diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
index 1cc175d3c25c..41470c4dba02 100644
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
@@ -99,7 +99,6 @@ static void pruss_cleanup(struct device *dev, struct uio_pruss_dev *gdev)
for (cnt = 0; cnt < MAX_PRUSS_EVT; cnt++, p++) {
uio_unregister_device(p);
- kfree(p->name);
}
iounmap(gdev->prussio_vaddr);
if (gdev->ddr_vaddr) {
@@ -110,10 +109,8 @@ static void pruss_cleanup(struct device *dev, struct uio_pruss_dev *gdev)
gen_pool_free(gdev->sram_pool,
gdev->sram_vaddr,
sram_pool_sz);
- kfree(gdev->info);
clk_disable(gdev->pruss_clk);
clk_put(gdev->pruss_clk);
- kfree(gdev);
}
static int pruss_probe(struct platform_device *pdev)
@@ -125,22 +122,19 @@ static int pruss_probe(struct platform_device *pdev)
int ret, cnt, i, len;
struct uio_pruss_pdata *pdata = dev_get_platdata(dev);
- gdev = kzalloc(sizeof(struct uio_pruss_dev), GFP_KERNEL);
+ gdev = devm_kzalloc(dev, sizeof(struct uio_pruss_dev), GFP_KERNEL);
if (!gdev)
return -ENOMEM;
- gdev->info = kcalloc(MAX_PRUSS_EVT, sizeof(*p), GFP_KERNEL);
- if (!gdev->info) {
- ret = -ENOMEM;
- goto err_free_gdev;
- }
+ gdev->info = devm_kcalloc(dev, MAX_PRUSS_EVT, sizeof(*p), GFP_KERNEL);
+ if (!gdev->info)
+ return -ENOMEM;
/* Power on PRU in case its not done as part of boot-loader */
gdev->pruss_clk = clk_get(dev, "pruss");
if (IS_ERR(gdev->pruss_clk)) {
dev_err(dev, "Failed to get clock\n");
- ret = PTR_ERR(gdev->pruss_clk);
- goto err_free_info;
+ return PTR_ERR(gdev->pruss_clk);
}
ret = clk_enable(gdev->pruss_clk);
@@ -206,7 +200,7 @@ static int pruss_probe(struct platform_device *pdev)
p->mem[2].size = extram_pool_sz;
p->mem[2].memtype = UIO_MEM_PHYS;
- p->name = kasprintf(GFP_KERNEL, "pruss_evt%d", cnt);
+ p->name = devm_kasprintf(dev, GFP_KERNEL, "pruss_evt%d", cnt);
p->version = DRV_VERSION;
/* Register PRUSS IRQ lines */
@@ -215,10 +209,8 @@ static int pruss_probe(struct platform_device *pdev)
p->priv = gdev;
ret = uio_register_device(dev, p);
- if (ret < 0) {
- kfree(p->name);
+ if (ret < 0)
goto err_unloop;
- }
}
platform_set_drvdata(pdev, gdev);
@@ -227,7 +219,6 @@ static int pruss_probe(struct platform_device *pdev)
err_unloop:
for (i = 0, p = gdev->info; i < cnt; i++, p++) {
uio_unregister_device(p);
- kfree(p->name);
}
iounmap(gdev->prussio_vaddr);
err_free_ddr_vaddr:
@@ -240,10 +231,6 @@ static int pruss_probe(struct platform_device *pdev)
clk_disable(gdev->pruss_clk);
err_clk_put:
clk_put(gdev->pruss_clk);
-err_free_info:
- kfree(gdev->info);
-err_free_gdev:
- kfree(gdev);
return ret;
}
--
2.17.1
This change uses devm_clk_get() to obtain a reference to the clock. It has
the benefit that clk_put() is no longer required, and cleans up the exit &
error path.
Signed-off-by: Alexandru Ardelean <[email protected]>
---
drivers/uio/uio_pruss.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
index 41470c4dba02..f50464c2a0bf 100644
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
@@ -110,7 +110,6 @@ static void pruss_cleanup(struct device *dev, struct uio_pruss_dev *gdev)
gdev->sram_vaddr,
sram_pool_sz);
clk_disable(gdev->pruss_clk);
- clk_put(gdev->pruss_clk);
}
static int pruss_probe(struct platform_device *pdev)
@@ -131,16 +130,16 @@ static int pruss_probe(struct platform_device *pdev)
return -ENOMEM;
/* Power on PRU in case its not done as part of boot-loader */
- gdev->pruss_clk = clk_get(dev, "pruss");
+ gdev->pruss_clk = devm_clk_get(dev, "pruss");
if (IS_ERR(gdev->pruss_clk)) {
dev_err(dev, "Failed to get clock\n");
- return PTR_ERR(gdev->pruss_clk);
+ return ret;
}
ret = clk_enable(gdev->pruss_clk);
if (ret) {
dev_err(dev, "Failed to enable clock\n");
- goto err_clk_put;
+ return ret;
}
regs_prussio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -229,8 +228,6 @@ static int pruss_probe(struct platform_device *pdev)
gen_pool_free(gdev->sram_pool, gdev->sram_vaddr, sram_pool_sz);
err_clk_disable:
clk_disable(gdev->pruss_clk);
-err_clk_put:
- clk_put(gdev->pruss_clk);
return ret;
}
--
2.17.1
Hi Alexandru,
I love your patch! Perhaps something to improve:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on linus/master linux/master v5.10-rc3 next-20201113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Alexandru-Ardelean/uio-pruss-move-simple-allocations-to-dem_-equivalents/20201111-192014
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 1987f112f1425cba2671d878f6952087e9456a0a
config: riscv-randconfig-r003-20201111 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 874b0a0b9db93f5d3350ffe6b5efda2d908415d0)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/37416440d4299a08c6f1a2dc448f7e9249f303ad
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alexandru-Ardelean/uio-pruss-move-simple-allocations-to-dem_-equivalents/20201111-192014
git checkout 37416440d4299a08c6f1a2dc448f7e9249f303ad
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> drivers/uio/uio_pruss.c:136:10: warning: variable 'ret' is uninitialized when used here [-Wuninitialized]
return ret;
^~~
drivers/uio/uio_pruss.c:121:9: note: initialize the variable 'ret' to silence this warning
int ret, cnt, i, len;
^
= 0
1 warning generated.
vim +/ret +136 drivers/uio/uio_pruss.c
114
115 static int pruss_probe(struct platform_device *pdev)
116 {
117 struct uio_info *p;
118 struct uio_pruss_dev *gdev;
119 struct resource *regs_prussio;
120 struct device *dev = &pdev->dev;
121 int ret, cnt, i, len;
122 struct uio_pruss_pdata *pdata = dev_get_platdata(dev);
123
124 gdev = devm_kzalloc(dev, sizeof(struct uio_pruss_dev), GFP_KERNEL);
125 if (!gdev)
126 return -ENOMEM;
127
128 gdev->info = devm_kcalloc(dev, MAX_PRUSS_EVT, sizeof(*p), GFP_KERNEL);
129 if (!gdev->info)
130 return -ENOMEM;
131
132 /* Power on PRU in case its not done as part of boot-loader */
133 gdev->pruss_clk = devm_clk_get(dev, "pruss");
134 if (IS_ERR(gdev->pruss_clk)) {
135 dev_err(dev, "Failed to get clock\n");
> 136 return ret;
137 }
138
139 ret = clk_enable(gdev->pruss_clk);
140 if (ret) {
141 dev_err(dev, "Failed to enable clock\n");
142 return ret;
143 }
144
145 regs_prussio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
146 if (!regs_prussio) {
147 dev_err(dev, "No PRUSS I/O resource specified\n");
148 ret = -EIO;
149 goto err_clk_disable;
150 }
151
152 if (!regs_prussio->start) {
153 dev_err(dev, "Invalid memory resource\n");
154 ret = -EIO;
155 goto err_clk_disable;
156 }
157
158 if (pdata->sram_pool) {
159 gdev->sram_pool = pdata->sram_pool;
160 gdev->sram_vaddr =
161 (unsigned long)gen_pool_dma_alloc(gdev->sram_pool,
162 sram_pool_sz, &gdev->sram_paddr);
163 if (!gdev->sram_vaddr) {
164 dev_err(dev, "Could not allocate SRAM pool\n");
165 ret = -ENOMEM;
166 goto err_clk_disable;
167 }
168 }
169
170 gdev->ddr_vaddr = dma_alloc_coherent(dev, extram_pool_sz,
171 &(gdev->ddr_paddr), GFP_KERNEL | GFP_DMA);
172 if (!gdev->ddr_vaddr) {
173 dev_err(dev, "Could not allocate external memory\n");
174 ret = -ENOMEM;
175 goto err_free_sram;
176 }
177
178 len = resource_size(regs_prussio);
179 gdev->prussio_vaddr = ioremap(regs_prussio->start, len);
180 if (!gdev->prussio_vaddr) {
181 dev_err(dev, "Can't remap PRUSS I/O address range\n");
182 ret = -ENOMEM;
183 goto err_free_ddr_vaddr;
184 }
185
186 gdev->pintc_base = pdata->pintc_base;
187 gdev->hostirq_start = platform_get_irq(pdev, 0);
188
189 for (cnt = 0, p = gdev->info; cnt < MAX_PRUSS_EVT; cnt++, p++) {
190 p->mem[0].addr = regs_prussio->start;
191 p->mem[0].size = resource_size(regs_prussio);
192 p->mem[0].memtype = UIO_MEM_PHYS;
193
194 p->mem[1].addr = gdev->sram_paddr;
195 p->mem[1].size = sram_pool_sz;
196 p->mem[1].memtype = UIO_MEM_PHYS;
197
198 p->mem[2].addr = gdev->ddr_paddr;
199 p->mem[2].size = extram_pool_sz;
200 p->mem[2].memtype = UIO_MEM_PHYS;
201
202 p->name = devm_kasprintf(dev, GFP_KERNEL, "pruss_evt%d", cnt);
203 p->version = DRV_VERSION;
204
205 /* Register PRUSS IRQ lines */
206 p->irq = gdev->hostirq_start + cnt;
207 p->handler = pruss_handler;
208 p->priv = gdev;
209
210 ret = uio_register_device(dev, p);
211 if (ret < 0)
212 goto err_unloop;
213 }
214
215 platform_set_drvdata(pdev, gdev);
216 return 0;
217
218 err_unloop:
219 for (i = 0, p = gdev->info; i < cnt; i++, p++) {
220 uio_unregister_device(p);
221 }
222 iounmap(gdev->prussio_vaddr);
223 err_free_ddr_vaddr:
224 dma_free_coherent(dev, extram_pool_sz, gdev->ddr_vaddr,
225 gdev->ddr_paddr);
226 err_free_sram:
227 if (pdata->sram_pool)
228 gen_pool_free(gdev->sram_pool, gdev->sram_vaddr, sram_pool_sz);
229 err_clk_disable:
230 clk_disable(gdev->pruss_clk);
231
232 return ret;
233 }
234
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
This change uses devm_clk_get() to obtain a reference to the clock. It has
the benefit that clk_put() is no longer required, and cleans up the exit &
error path.
Signed-off-by: Alexandru Ardelean <[email protected]>
---
Changelog v1 -> v2:
* reverted silly/goofed `return ret` to `return PTR_ERR(gdev->pruss_clk);`
this caused a warning about `ret` being uninitialized
drivers/uio/uio_pruss.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
index 41470c4dba02..e9096f53b4cc 100644
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
@@ -110,7 +110,6 @@ static void pruss_cleanup(struct device *dev, struct uio_pruss_dev *gdev)
gdev->sram_vaddr,
sram_pool_sz);
clk_disable(gdev->pruss_clk);
- clk_put(gdev->pruss_clk);
}
static int pruss_probe(struct platform_device *pdev)
@@ -131,7 +130,7 @@ static int pruss_probe(struct platform_device *pdev)
return -ENOMEM;
/* Power on PRU in case its not done as part of boot-loader */
- gdev->pruss_clk = clk_get(dev, "pruss");
+ gdev->pruss_clk = devm_clk_get(dev, "pruss");
if (IS_ERR(gdev->pruss_clk)) {
dev_err(dev, "Failed to get clock\n");
return PTR_ERR(gdev->pruss_clk);
@@ -140,7 +139,7 @@ static int pruss_probe(struct platform_device *pdev)
ret = clk_enable(gdev->pruss_clk);
if (ret) {
dev_err(dev, "Failed to enable clock\n");
- goto err_clk_put;
+ return ret;
}
regs_prussio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -229,8 +228,6 @@ static int pruss_probe(struct platform_device *pdev)
gen_pool_free(gdev->sram_pool, gdev->sram_vaddr, sram_pool_sz);
err_clk_disable:
clk_disable(gdev->pruss_clk);
-err_clk_put:
- clk_put(gdev->pruss_clk);
return ret;
}
--
2.17.1