axonram: Adjustments for axon_ram_probe()
Subsystems (2)
cover axonram: Adjustments for axon_ram_probe()
From: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 21:02:02 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (4):
Delete an error message for a failed memory allocation Improve a size determination in axon_ram_probe() Return directly after a failed kzalloc() Delete an unnecessary variable initialisation
arch/powerpc/sysdev/axonram.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-)
Signature · 1 line
2.13.4
PATCH 1/4 axonram: Delete an error message for a failed memory allocation in axon_ram_probe()
From: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 19:49:18 +0200
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- arch/powerpc/sysdev/axonram.c | 1 - 1 file changed, 1 deletion(-)
arch/powerpc/sysdev/axonram.c +0 -1
@@ -193,7 +193,6 @@ static int axon_ram_probe(struct platform_device *device) bank =kzalloc (sizeof (struct axon_ram_bank ),GFP_KERNEL );if (bank =NULL ) { -dev_err (&device->dev,"Out of memory\n" ); rc = -ENOMEM ; goto failed; }
Signature · 1 line
2.13.4
PATCH 2/4 axonram: Improve a size determination in axon_ram_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 20:00:16 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
--- arch/powerpc/sysdev/axonram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/axonram.c +1 -1
@@ -191,7 +191,7 @@ static int axon_ram_probe(struct platform_device *device)dev_info (&device->dev,"Found memory controller on %s\n" , device->dev.of_node->full_name); - bank =kzalloc (sizeof (struct axon_ram_bank ),GFP_KERNEL ); + bank =kzalloc (sizeof (*bank),GFP_KERNEL );if (bank =NULL ) { rc = -ENOMEM ; goto failed;
Signature · 1 line
2.13.4
PATCH 3/4 axonram: Return directly after a failed kzalloc() in axon_ram_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 20:23:57 +0200
* Return directly after a call of the function "kzalloc" failed at the beginning.
* Delete a repeated check for the local variable "bank" which became unnecessary with this refactoring.
--- arch/powerpc/sysdev/axonram.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-)
arch/powerpc/sysdev/axonram.c +17 -22
@@ -192,10 +192,8 @@ static int axon_ram_probe(struct platform_device *device) device->dev.of_node->full_name); bank =kzalloc (sizeof (*bank),GFP_KERNEL ); -if (bank =NULL ) { - rc = -ENOMEM ; - goto failed; - } +if (!bank) +return -ENOMEM ; device->dev.platform_data = bank;
@@ -291,25 +289,22 @@ static int axon_ram_probe(struct platform_device *device)return 0 ; failed: -if (bank !=NULL ) { -if (bank->irq_id) -free_irq (bank->irq_id, device); -if (bank->disk !=NULL ) { -if (bank->disk->major >0 ) -unregister_blkdev (bank->disk->major, - bank->disk->disk_name); -if (bank->disk->flags &GENHD_FL_UP ) -del_gendisk (bank->disk); -put_disk (bank->disk); - } -kill_dax (bank->dax_dev); -put_dax (bank->dax_dev); - device->dev.platform_data =NULL ; -if (bank->io_addr !=0 ) -iounmap ((void __iomem *) bank->io_addr); -kfree (bank); +if (bank->irq_id) +free_irq (bank->irq_id, device); +if (bank->disk !=NULL ) { +if (bank->disk->major >0 ) +unregister_blkdev (bank->disk->major, + bank->disk->disk_name); +if (bank->disk->flags &GENHD_FL_UP ) +del_gendisk (bank->disk); +put_disk (bank->disk); } - +kill_dax (bank->dax_dev); +put_dax (bank->dax_dev); + device->dev.platform_data =NULL ; +if (bank->io_addr !=0 ) +iounmap ((void __iomem *) bank->io_addr); +kfree (bank);return rc; }
Signature · 1 line
2.13.4
PATCH 4/4 axonram: Delete an unnecessary variable initialisation in axon_ram_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 20:34:00 +0200
The local variable "rc" will eventually be set only to an error code. Thus omit the explicit initialisation at the beginning.
--- arch/powerpc/sysdev/axonram.c | 1 - 1 file changed, 1 deletion(-)
arch/powerpc/sysdev/axonram.c +0 -1
@@ -184,7 +184,6 @@ static int axon_ram_probe(struct platform_device *device)static int axon_ram_bank_id =-1 ;struct axon_ram_bank *bank;struct resource resource; -int rc =0 ; axon_ram_bank_id++;
Signature · 1 line
2.13.4
kbuild test robot
build botRe: [PATCH 4/4] axonram: Delete an unnecessary variable initialisation in axon_ram_probe()
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…
Hi Markus,
[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.13-rc3 next-20170804]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/SF-Markus-Elfring/axonram-Adjustments-for-axon_ram_probe/20170804-170436 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next config: powerpc-defconfig (attached as .config) compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=powerpc
All errors (new ones prefixed by >>):
arch/powerpc/sysdev/axonram.c: In function 'axon_ram_probe':
>> arch/powerpc/sysdev/axonram.c:203:3: error: 'rc' undeclared (first use in this function)
rc = -EFAULT;
^~
arch/powerpc/sysdev/axonram.c:203:3: note: each undeclared identifier is reported only once for each function it appears in
arch/powerpc/sysdev/axonram.c:308:1: error: control reaches end of non-void function [-Werror=return-type]
}
^cc1: all warnings being treated as errors
vim +/rc +203 arch/powerpc/sysdev/axonram.c
dbdf04c40 Maxim Shchetynin 2007-07-20 177
dbdf04c40 Maxim Shchetynin 2007-07-20 178 /**
dbdf04c40 Maxim Shchetynin 2007-07-20 179 * axon_ram_probe - probe() method for platform driver
000061245 Grant Likely 2011-02-22 180 * @device: see platform_driver method
dbdf04c40 Maxim Shchetynin 2007-07-20 181 */
000061245 Grant Likely 2011-02-22 182 static int axon_ram_probe(struct platform_device *device)
dbdf04c40 Maxim Shchetynin 2007-07-20 183 {
dbdf04c40 Maxim Shchetynin 2007-07-20 184 static int axon_ram_bank_id = -1;
dbdf04c40 Maxim Shchetynin 2007-07-20 185 struct axon_ram_bank *bank;
dbdf04c40 Maxim Shchetynin 2007-07-20 186 struct resource resource;
dbdf04c40 Maxim Shchetynin 2007-07-20 187
dbdf04c40 Maxim Shchetynin 2007-07-20 188 axon_ram_bank_id++;
dbdf04c40 Maxim Shchetynin 2007-07-20 189
dbdf04c40 Maxim Shchetynin 2007-07-20 190 dev_info(&device->dev, "Found memory controller on %s\n",
61c7a080a Grant Likely 2010-04-13 191 device->dev.of_node->full_name);
dbdf04c40 Maxim Shchetynin 2007-07-20 192
12d94c464 Markus Elfring 2017-08-03 193 bank = kzalloc(sizeof(*bank), GFP_KERNEL);
e54eff030 Markus Elfring 2017-08-03 194 if (!bank)
e54eff030 Markus Elfring 2017-08-03 195 return -ENOMEM;
dbdf04c40 Maxim Shchetynin 2007-07-20 196
dbdf04c40 Maxim Shchetynin 2007-07-20 197 device->dev.platform_data = bank;
dbdf04c40 Maxim Shchetynin 2007-07-20 198
dbdf04c40 Maxim Shchetynin 2007-07-20 199 bank->device = device;
dbdf04c40 Maxim Shchetynin 2007-07-20 200
61c7a080a Grant Likely 2010-04-13 201 if (of_address_to_resource(device->dev.of_node, 0, &resource) != 0) {
dbdf04c40 Maxim Shchetynin 2007-07-20 202 dev_err(&device->dev, "Cannot access device tree\n");
dbdf04c40 Maxim Shchetynin 2007-07-20 @203 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 204 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 205 }
dbdf04c40 Maxim Shchetynin 2007-07-20 206
28f65c11f Joe Perches 2011-06-09 207 bank->size = resource_size(&resource);
dbdf04c40 Maxim Shchetynin 2007-07-20 208
dbdf04c40 Maxim Shchetynin 2007-07-20 209 if (bank->size == 0) {
dbdf04c40 Maxim Shchetynin 2007-07-20 210 dev_err(&device->dev, "No DDR2 memory found for %s%d\n",
dbdf04c40 Maxim Shchetynin 2007-07-20 211 AXON_RAM_DEVICE_NAME, axon_ram_bank_id);
dbdf04c40 Maxim Shchetynin 2007-07-20 212 rc = -ENODEV;
dbdf04c40 Maxim Shchetynin 2007-07-20 213 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 214 }
dbdf04c40 Maxim Shchetynin 2007-07-20 215
dbdf04c40 Maxim Shchetynin 2007-07-20 216 dev_info(&device->dev, "Register DDR2 memory device %s%d with %luMB\n",
dbdf04c40 Maxim Shchetynin 2007-07-20 217 AXON_RAM_DEVICE_NAME, axon_ram_bank_id, bank->size >> 20);
dbdf04c40 Maxim Shchetynin 2007-07-20 218
dbdf04c40 Maxim Shchetynin 2007-07-20 219 bank->ph_addr = resource.start;
40f1ce7fb Anton Blanchard 2011-05-08 220 bank->io_addr = (unsigned long) ioremap_prot(
dbdf04c40 Maxim Shchetynin 2007-07-20 221 bank->ph_addr, bank->size, _PAGE_NO_CACHE);
dbdf04c40 Maxim Shchetynin 2007-07-20 222 if (bank->io_addr == 0) {
dbdf04c40 Maxim Shchetynin 2007-07-20 223 dev_err(&device->dev, "ioremap() failed\n");
dbdf04c40 Maxim Shchetynin 2007-07-20 224 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 225 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 226 }
dbdf04c40 Maxim Shchetynin 2007-07-20 227
dbdf04c40 Maxim Shchetynin 2007-07-20 228 bank->disk = alloc_disk(AXON_RAM_MINORS_PER_DISK);
dbdf04c40 Maxim Shchetynin 2007-07-20 229 if (bank->disk == NULL) {
dbdf04c40 Maxim Shchetynin 2007-07-20 230 dev_err(&device->dev, "Cannot register disk\n");
dbdf04c40 Maxim Shchetynin 2007-07-20 231 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 232 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 233 }
dbdf04c40 Maxim Shchetynin 2007-07-20 234
60fcd55cc Dan Williams 2017-01-25 235
9a23409b6 Maxim Shchetynin 2008-07-16 236 bank->disk->major = azfs_major;
9a23409b6 Maxim Shchetynin 2008-07-16 237 bank->disk->first_minor = azfs_minor;
dbdf04c40 Maxim Shchetynin 2007-07-20 238 bank->disk->fops = &axon_ram_devops;
dbdf04c40 Maxim Shchetynin 2007-07-20 239 bank->disk->private_data = bank;
dbdf04c40 Maxim Shchetynin 2007-07-20 240
dbdf04c40 Maxim Shchetynin 2007-07-20 241 sprintf(bank->disk->disk_name, "%s%d",
dbdf04c40 Maxim Shchetynin 2007-07-20 242 AXON_RAM_DEVICE_NAME, axon_ram_bank_id);
dbdf04c40 Maxim Shchetynin 2007-07-20 243
60fcd55cc Dan Williams 2017-01-25 244 bank->dax_dev = alloc_dax(bank, bank->disk->disk_name,
60fcd55cc Dan Williams 2017-01-25 245 &axon_ram_dax_ops);
60fcd55cc Dan Williams 2017-01-25 246 if (!bank->dax_dev) {
60fcd55cc Dan Williams 2017-01-25 247 rc = -ENOMEM;
60fcd55cc Dan Williams 2017-01-25 248 goto failed;
60fcd55cc Dan Williams 2017-01-25 249 }
60fcd55cc Dan Williams 2017-01-25 250
dbdf04c40 Maxim Shchetynin 2007-07-20 251 bank->disk->queue = blk_alloc_queue(GFP_KERNEL);
dbdf04c40 Maxim Shchetynin 2007-07-20 252 if (bank->disk->queue == NULL) {
dbdf04c40 Maxim Shchetynin 2007-07-20 253 dev_err(&device->dev, "Cannot register disk queue\n");
dbdf04c40 Maxim Shchetynin 2007-07-20 254 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 255 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 256 }
dbdf04c40 Maxim Shchetynin 2007-07-20 257
dbdf04c40 Maxim Shchetynin 2007-07-20 258 set_capacity(bank->disk, bank->size >> AXON_RAM_SECTOR_SHIFT);
dbdf04c40 Maxim Shchetynin 2007-07-20 259 blk_queue_make_request(bank->disk->queue, axon_ram_make_request);
e1defc4ff Martin K. Petersen 2009-05-22 260 blk_queue_logical_block_size(bank->disk->queue, AXON_RAM_SECTOR_SIZE);
0d52c756a Dan Williams 2016-06-15 261 device_add_disk(&device->dev, bank->disk);
dbdf04c40 Maxim Shchetynin 2007-07-20 262
61c7a080a Grant Likely 2010-04-13 263 bank->irq_id = irq_of_parse_and_map(device->dev.of_node, 0);
ef24ba709 Michael Ellerman 2016-09-06 264 if (!bank->irq_id) {
dbdf04c40 Maxim Shchetynin 2007-07-20 265 dev_err(&device->dev, "Cannot access ECC interrupt ID\n");
dbdf04c40 Maxim Shchetynin 2007-07-20 266 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 267 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 268 }
dbdf04c40 Maxim Shchetynin 2007-07-20 269
fedcd2c53 Maxim Shchetynin 2007-08-23 270 rc = request_irq(bank->irq_id, axon_ram_irq_handler,
dbdf04c40 Maxim Shchetynin 2007-07-20 271 AXON_RAM_IRQ_FLAGS, bank->disk->disk_name, device);
dbdf04c40 Maxim Shchetynin 2007-07-20 272 if (rc != 0) {
dbdf04c40 Maxim Shchetynin 2007-07-20 273 dev_err(&device->dev, "Cannot register ECC interrupt handler\n");
ef24ba709 Michael Ellerman 2016-09-06 274 bank->irq_id = 0;
dbdf04c40 Maxim Shchetynin 2007-07-20 275 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 276 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 277 }
dbdf04c40 Maxim Shchetynin 2007-07-20 278
dbdf04c40 Maxim Shchetynin 2007-07-20 279 rc = device_create_file(&device->dev, &dev_attr_ecc);
dbdf04c40 Maxim Shchetynin 2007-07-20 280 if (rc != 0) {
dbdf04c40 Maxim Shchetynin 2007-07-20 281 dev_err(&device->dev, "Cannot create sysfs file\n");
dbdf04c40 Maxim Shchetynin 2007-07-20 282 rc = -EFAULT;
dbdf04c40 Maxim Shchetynin 2007-07-20 283 goto failed;
dbdf04c40 Maxim Shchetynin 2007-07-20 284 }
dbdf04c40 Maxim Shchetynin 2007-07-20 285
9a23409b6 Maxim Shchetynin 2008-07-16 286 azfs_minor += bank->disk->minors;
9a23409b6 Maxim Shchetynin 2008-07-16 287
dbdf04c40 Maxim Shchetynin 2007-07-20 288 return 0;
dbdf04c40 Maxim Shchetynin 2007-07-20 289
dbdf04c40 Maxim Shchetynin 2007-07-20 290 failed:
ef24ba709 Michael Ellerman 2016-09-06 291 if (bank->irq_id)
fedcd2c53 Maxim Shchetynin 2007-08-23 292 free_irq(bank->irq_id, device);
dbdf04c40 Maxim Shchetynin 2007-07-20 293 if (bank->disk != NULL) {
dbdf04c40 Maxim Shchetynin 2007-07-20 294 if (bank->disk->major > 0)
dbdf04c40 Maxim Shchetynin 2007-07-20 295 unregister_blkdev(bank->disk->major,
dbdf04c40 Maxim Shchetynin 2007-07-20 296 bank->disk->disk_name);
672a2c87c Jan Kara 2017-03-08 297 if (bank->disk->flags & GENHD_FL_UP)
dbdf04c40 Maxim Shchetynin 2007-07-20 298 del_gendisk(bank->disk);
672a2c87c Jan Kara 2017-03-08 299 put_disk(bank->disk);
dbdf04c40 Maxim Shchetynin 2007-07-20 300 }
60fcd55cc Dan Williams 2017-01-25 301 kill_dax(bank->dax_dev);
60fcd55cc Dan Williams 2017-01-25 302 put_dax(bank->dax_dev);
dbdf04c40 Maxim Shchetynin 2007-07-20 303 device->dev.platform_data = NULL;
dbdf04c40 Maxim Shchetynin 2007-07-20 304 if (bank->io_addr != 0)
dbdf04c40 Maxim Shchetynin 2007-07-20 305 iounmap((void __iomem *) bank->io_addr);
dbdf04c40 Maxim Shchetynin 2007-07-20 306 kfree(bank);
dbdf04c40 Maxim Shchetynin 2007-07-20 307 return rc;
dbdf04c40 Maxim Shchetynin 2007-07-20 308 }
dbdf04c40 Maxim Shchetynin 2007-07-20 309 :::::: The code at line 203 was first introduced by commit
:::::: dbdf04c40161f81d74e27f04e201acb3a5dfad69 [CELL] driver for DDR2 memory on AXON
:::::: TO: Maxim Shchetynin <[email protected]> :::::: CC: Arnd Bergmann <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 4/4] axonram: Delete an unnecessary variable initialisation in axon_ram_probe()
In reply to SF Markus ElfringQuoted 16 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 20:34:00 +0200The local variable "rc" will eventually be set only to an error code. Thus omit the explicit initialisation at the beginning.
Signed-off-by Markus Elfring <[email protected]>--- arch/powerpc/sysdev/axonram.c | 1 - 1 file changed, 1 deletion(-)arch/powerpc/sysdev/axonram.c +0
-0
arch/powerpc/sysdev/axonram.c static int axon_ram_probe(struct platform_device *device) · line 187
Quoted 4 lines
arch/powerpc/sysdev/axonram.c +0
-1@@ -184,7 +184,6 @@ static int axon_ram_probe(struct platform_device *device)static int axon_ram_bank_id =-1 ;struct axon_ram_bank *bank;struct resource resource; -int rc =0 ;
You've completely removed the decleration of "rc" instead of removing the "= 0" initialization. I would expect a compilation test to have turned up an undeclared use error for "rc".
-Tyrel
Quoted 3 lines
arch/powerpc/sysdev/axonram.c +0
-0axon_ram_bank_id++;
Re: [1/4] axonram: Delete an error message for a failed memory allocation in axon_ram_probe()
In reply to SF Markus ElfringQuoted 9 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 3 Aug 2017 19:49:18 +0200Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a1bddf3991573f3dff2762bfca5e11
cheers
Re: axonram: Delete an error message for a failed memory allocation in axon_ram_probe()
Quoted 1 line
Series applied to powerpc next, thanks.
Thanks for another positive feedback.
But I wonder how you can refer to the “series” when the forth update step “Delete an unnecessary variable initialisation” contained a broken suggestion.
This link seems to refer (only?) to the update step “Improve a size determination”. How is the status for the other two change possibilities of this software module?
Regards,
Markus
PATCH v2 1/1 axonram: Delete an unnecessary variable initialisation in axon_ram_probe()
In reply to kbuild test robotFrom: Markus Elfring <[email protected]>
Date: Tue, 5 Sep 2017 18:47:02 +0200
The local variable "rc" will eventually be set only to an error code. Thus omit the explicit initialisation at the beginning.
---
v2:
Three update steps were integrated for this software module on 2017-09-01. Thus improve another source code place.
arch/powerpc/sysdev/axonram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/sysdev/axonram.c +1 -1
@@ -184,7 +184,7 @@ static int axon_ram_probe(struct platform_device *device)static int axon_ram_bank_id =-1 ;struct axon_ram_bank *bank;struct resource resource; -int rc =0 ; +int rc; axon_ram_bank_id++;
Signature · 1 line
2.14.1
Michael Ellerman
AppliedRe: [v2] axonram: Delete an unnecessary variable initialisation in axon_ram_probe()
Quoted 7 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Tue, 5 Sep 2017 18:47:02 +0200The local variable "rc" will eventually be set only to an error code. Thus omit the explicit initialisation at the beginning.
Signed-off-by Markus Elfring <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/a7cd4586210c69c19aef26f4f83d3e
cheers