Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751566AbdG0GFZ (ORCPT ); Thu, 27 Jul 2017 02:05:25 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:13014 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751452AbdG0GFY (ORCPT ); Thu, 27 Jul 2017 02:05:24 -0400 Subject: Re: [PATCH][next] clk: ti: check for null return in strrchr to avoid null dereferencing To: Colin King , Michael Turquette , Stephen Boyd , , CC: References: <20170726235627.9163-1-colin.king@canonical.com> From: Tero Kristo Message-ID: Date: Thu, 27 Jul 2017 09:05:13 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170726235627.9163-1-colin.king@canonical.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1147 Lines: 32 On 27/07/17 02:56, Colin King wrote: > From: Colin Ian King > > 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 > --- > 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