diff mbox

[next] clk: ti: check for null return in strrchr to avoid null dereferencing

Message ID 20170726235627.9163-1-colin.king@canonical.com (mailing list archive)
State Under Review
Delegated to: Stephen Boyd
Headers show

Commit Message

Colin King July 26, 2017, 11:56 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

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>
---
 drivers/clk/ti/adpll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tero Kristo July 27, 2017, 6:05 a.m. UTC | #1
On 27/07/17 02:56, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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>
> ---
>   drivers/clk/ti/adpll.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
> index 255cafb18336..bd7cb9a413c9 100644
> --- a/drivers/clk/ti/adpll.c
> +++ b/drivers/clk/ti/adpll.c
> @@ -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);
> 

Looks fine to me.

Acked-by: Tero Kristo <t-kristo@ti.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-clk" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stephen Boyd Sept. 1, 2017, 1:45 a.m. UTC | #2
On 07/27, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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>
> ---

Applied to clk-next
diff mbox

Patch

diff --git a/drivers/clk/ti/adpll.c b/drivers/clk/ti/adpll.c
index 255cafb18336..bd7cb9a413c9 100644
--- a/drivers/clk/ti/adpll.c
+++ b/drivers/clk/ti/adpll.c
@@ -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);