.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * RapidIO enumeration and discovery support |
---|
3 | 4 | * |
---|
.. | .. |
---|
11 | 12 | * Copyright 2009 Sysgo AG |
---|
12 | 13 | * Thomas Moll <thomas.moll@sysgo.com> |
---|
13 | 14 | * - Added Input- Output- enable functionality, to allow full communication |
---|
14 | | - * |
---|
15 | | - * This program is free software; you can redistribute it and/or modify it |
---|
16 | | - * under the terms of the GNU General Public License as published by the |
---|
17 | | - * Free Software Foundation; either version 2 of the License, or (at your |
---|
18 | | - * option) any later version. |
---|
19 | 15 | */ |
---|
20 | 16 | |
---|
21 | 17 | #include <linux/types.h> |
---|
.. | .. |
---|
43 | 39 | u16 start; /* logical minimal id */ |
---|
44 | 40 | u32 max; /* max number of IDs in table */ |
---|
45 | 41 | spinlock_t lock; |
---|
46 | | - unsigned long table[0]; |
---|
| 42 | + unsigned long table[]; |
---|
47 | 43 | }; |
---|
48 | 44 | |
---|
49 | 45 | static int next_destid = 0; |
---|
.. | .. |
---|
334 | 330 | size_t size; |
---|
335 | 331 | u32 swpinfo = 0; |
---|
336 | 332 | |
---|
337 | | - size = sizeof(struct rio_dev); |
---|
| 333 | + size = sizeof(*rdev); |
---|
338 | 334 | if (rio_mport_read_config_32(port, destid, hopcount, |
---|
339 | 335 | RIO_PEF_CAR, &result)) |
---|
340 | 336 | return NULL; |
---|
.. | .. |
---|
342 | 338 | if (result & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) { |
---|
343 | 339 | rio_mport_read_config_32(port, destid, hopcount, |
---|
344 | 340 | RIO_SWP_INFO_CAR, &swpinfo); |
---|
345 | | - if (result & RIO_PEF_SWITCH) { |
---|
346 | | - size += (RIO_GET_TOTAL_PORTS(swpinfo) * |
---|
347 | | - sizeof(rswitch->nextdev[0])) + sizeof(*rswitch); |
---|
348 | | - } |
---|
| 341 | + if (result & RIO_PEF_SWITCH) |
---|
| 342 | + size += struct_size(rswitch, nextdev, RIO_GET_TOTAL_PORTS(swpinfo)); |
---|
349 | 343 | } |
---|
350 | 344 | |
---|
351 | 345 | rdev = kzalloc(size, GFP_KERNEL); |
---|
.. | .. |
---|
460 | 454 | 0, 0xffff); |
---|
461 | 455 | |
---|
462 | 456 | ret = rio_add_device(rdev); |
---|
463 | | - if (ret) |
---|
464 | | - goto cleanup; |
---|
| 457 | + if (ret) { |
---|
| 458 | + if (rswitch) |
---|
| 459 | + kfree(rswitch->route_table); |
---|
| 460 | + put_device(&rdev->dev); |
---|
| 461 | + return NULL; |
---|
| 462 | + } |
---|
465 | 463 | |
---|
466 | 464 | rio_dev_get(rdev); |
---|
467 | 465 | |
---|