Skip to content

Commit 8d53252

Browse files
author
Russell King (Oracle)
committed
clkdev: report over-sized strings when creating clkdev entries
Report an error when an attempt to register a clkdev entry results in a truncated string so the problem can be easily spotted. Reported by: Duanqiang Wen <[email protected]> Signed-off-by: Russell King (Oracle) <[email protected]>
1 parent e8f897f commit 8d53252

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

drivers/clk/clkdev.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,54 @@ vclkdev_alloc(struct clk_hw *hw, const char *con_id, const char *dev_fmt,
158158
va_list ap)
159159
{
160160
struct clk_lookup_alloc *cla;
161+
struct va_format vaf;
162+
const char *failure;
163+
va_list ap_copy;
164+
size_t max_size;
165+
ssize_t res;
161166

162167
cla = kzalloc(sizeof(*cla), GFP_KERNEL);
163168
if (!cla)
164169
return NULL;
165170

171+
va_copy(ap_copy, ap);
172+
166173
cla->cl.clk_hw = hw;
167174
if (con_id) {
168-
strscpy(cla->con_id, con_id, sizeof(cla->con_id));
175+
res = strscpy(cla->con_id, con_id, sizeof(cla->con_id));
176+
if (res < 0) {
177+
max_size = sizeof(cla->con_id);
178+
failure = "connection";
179+
goto fail;
180+
}
169181
cla->cl.con_id = cla->con_id;
170182
}
171183

172184
if (dev_fmt) {
173-
vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
185+
res = vsnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
186+
if (res >= sizeof(cla->dev_id)) {
187+
max_size = sizeof(cla->dev_id);
188+
failure = "device";
189+
goto fail;
190+
}
174191
cla->cl.dev_id = cla->dev_id;
175192
}
176193

194+
va_end(ap_copy);
195+
177196
return &cla->cl;
197+
198+
fail:
199+
if (dev_fmt)
200+
vaf.fmt = dev_fmt;
201+
else
202+
vaf.fmt = "null-device";
203+
vaf.va = &ap_copy;
204+
pr_err("%pV:%s: %s ID is greater than %zu\n",
205+
&vaf, con_id, failure, max_size);
206+
va_end(ap_copy);
207+
kfree(cla);
208+
return NULL;
178209
}
179210

180211
static struct clk_lookup *

0 commit comments

Comments
 (0)