Skip to content

Commit 34b95aa

Browse files
Simon Schwartzgregkh
authored andcommitted
driver core: platform: Prevent resouce overflow from causing infinite loops
[ Upstream commit 39cc539 ] num_resources in the platform_device struct is declared as a u32. The for loops that iterate over num_resources use an int as the counter, which can cause infinite loops on architectures with smaller ints. Change the loop counters to u32. Signed-off-by: Simon Schwartz <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ad4a9f6 commit 34b95aa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/base/platform.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/limits.h>
2929
#include <linux/property.h>
3030
#include <linux/kmemleak.h>
31+
#include <linux/types.h>
3132

3233
#include "base.h"
3334
#include "power/power.h"
@@ -68,7 +69,7 @@ void __weak arch_setup_pdev_archdata(struct platform_device *pdev)
6869
struct resource *platform_get_resource(struct platform_device *dev,
6970
unsigned int type, unsigned int num)
7071
{
71-
int i;
72+
u32 i;
7273

7374
for (i = 0; i < dev->num_resources; i++) {
7475
struct resource *r = &dev->resource[i];
@@ -153,7 +154,7 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
153154
unsigned int type,
154155
const char *name)
155156
{
156-
int i;
157+
u32 i;
157158

158159
for (i = 0; i < dev->num_resources; i++) {
159160
struct resource *r = &dev->resource[i];
@@ -350,7 +351,8 @@ EXPORT_SYMBOL_GPL(platform_device_add_properties);
350351
*/
351352
int platform_device_add(struct platform_device *pdev)
352353
{
353-
int i, ret;
354+
u32 i;
355+
int ret;
354356

355357
if (!pdev)
356358
return -EINVAL;
@@ -437,7 +439,7 @@ EXPORT_SYMBOL_GPL(platform_device_add);
437439
*/
438440
void platform_device_del(struct platform_device *pdev)
439441
{
440-
int i;
442+
u32 i;
441443

442444
if (pdev) {
443445
device_remove_properties(&pdev->dev);

0 commit comments

Comments
 (0)