clk: ti: check for null return in strrchr to avoid null dereferencing
authorColin Ian King <colin.king@canonical.com>
Wed, 26 Jul 2017 23:56:27 +0000 (00:56 +0100)
committerStephen Boyd <sboyd@codeaurora.org>
Fri, 1 Sep 2017 01:44:13 +0000 (18:44 -0700)
strrchr can potentially return a null so the following strlen on the
null pointer can cause a null dereference. Add a check to see if
the string postfix is not null before calling strlen.

Detected by CoverityScan, CID#1452039 ("Dereference null return")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Tero Kristo <t-kristo@ti.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
drivers/clk/ti/adpll.c

index d5c6db44631611d3ab57d999a5035ae476df3b28..d6036c788fab8fcbebb72bebbf9a6eaaccbda839 100644 (file)
@@ -222,7 +222,7 @@ static int ti_adpll_setup_clock(struct ti_adpll_data *d, struct clk *clock,
 
        /* Separate con_id in format "pll040dcoclkldo" to fit MAX_CON_ID */
        postfix = strrchr(name, '.');
-       if (strlen(postfix) > 1) {
+       if (postfix && strlen(postfix) > 1) {
                if (strlen(postfix) > ADPLL_MAX_CON_ID)
                        dev_warn(d->dev, "clock %s con_id lookup may fail\n",
                                 name);