[PATCH AUTOSEL for 3.18 14/63] of: fix of_device_get_modalias returned length when truncating buffers

From: Sasha Levin
Date: Sat Mar 03 2018 - 17:54:29 EST


From: Rob Herring <robh@xxxxxxxxxx>

[ Upstream commit bcf54d5385abaea9c8026aae6f4eeb348671a52d ]

If the length of the modalias is greater than the buffer size, then the
modalias is truncated. However the untruncated length is returned which
will cause an error. Fix this to return the truncated length. If an error
in the case was desired, then then we should just return -ENOMEM.

The reality is no device will ever have 4KB of compatible strings to hit
this case.

Signed-off-by: Rob Herring <robh@xxxxxxxxxx>
Cc: Frank Rowand <frowand.list@xxxxxxxxx>
Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxxxx>
---
drivers/of/device.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index de20165bad48..2ef5ca45a136 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -126,7 +126,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
str[i] = '_';
}

- return tsize;
+ return repend;
}
EXPORT_SYMBOL_GPL(of_device_get_modalias);

--
2.14.1