hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/rapidio/rio-scan.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * RapidIO enumeration and discovery support
34 *
....@@ -11,11 +12,6 @@
1112 * Copyright 2009 Sysgo AG
1213 * Thomas Moll <thomas.moll@sysgo.com>
1314 * - 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.
1915 */
2016
2117 #include <linux/types.h>
....@@ -43,7 +39,7 @@
4339 u16 start; /* logical minimal id */
4440 u32 max; /* max number of IDs in table */
4541 spinlock_t lock;
46
- unsigned long table[0];
42
+ unsigned long table[];
4743 };
4844
4945 static int next_destid = 0;
....@@ -334,7 +330,7 @@
334330 size_t size;
335331 u32 swpinfo = 0;
336332
337
- size = sizeof(struct rio_dev);
333
+ size = sizeof(*rdev);
338334 if (rio_mport_read_config_32(port, destid, hopcount,
339335 RIO_PEF_CAR, &result))
340336 return NULL;
....@@ -342,10 +338,8 @@
342338 if (result & (RIO_PEF_SWITCH | RIO_PEF_MULTIPORT)) {
343339 rio_mport_read_config_32(port, destid, hopcount,
344340 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));
349343 }
350344
351345 rdev = kzalloc(size, GFP_KERNEL);
....@@ -460,8 +454,12 @@
460454 0, 0xffff);
461455
462456 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
+ }
465463
466464 rio_dev_get(rdev);
467465