Skip to content

Commit 39cc539

Browse files
Simon Schwartzgregkh
authored andcommitted
driver core: platform: Prevent resouce overflow from causing infinite loops
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]>
1 parent 5bf33f0 commit 39cc539

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
@@ -27,6 +27,7 @@
2727
#include <linux/limits.h>
2828
#include <linux/property.h>
2929
#include <linux/kmemleak.h>
30+
#include <linux/types.h>
3031

3132
#include "base.h"
3233
#include "power/power.h"
@@ -48,7 +49,7 @@ EXPORT_SYMBOL_GPL(platform_bus);
4849
struct resource *platform_get_resource(struct platform_device *dev,
4950
unsigned int type, unsigned int num)
5051
{
51-
int i;
52+
u32 i;
5253

5354
for (i = 0; i < dev->num_resources; i++) {
5455
struct resource *r = &dev->resource[i];
@@ -255,7 +256,7 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
255256
unsigned int type,
256257
const char *name)
257258
{
258-
int i;
259+
u32 i;
259260

260261
for (i = 0; i < dev->num_resources; i++) {
261262
struct resource *r = &dev->resource[i];
@@ -501,7 +502,8 @@ EXPORT_SYMBOL_GPL(platform_device_add_properties);
501502
*/
502503
int platform_device_add(struct platform_device *pdev)
503504
{
504-
int i, ret;
505+
u32 i;
506+
int ret;
505507

506508
if (!pdev)
507509
return -EINVAL;
@@ -590,7 +592,7 @@ EXPORT_SYMBOL_GPL(platform_device_add);
590592
*/
591593
void platform_device_del(struct platform_device *pdev)
592594
{
593-
int i;
595+
u32 i;
594596

595597
if (!IS_ERR_OR_NULL(pdev)) {
596598
device_del(&pdev->dev);

0 commit comments

Comments
 (0)