[{"id":1761922,"web_url":"http://patchwork.ozlabs.org/comment/1761922/","msgid":"<20170901190835.GA14011@ulmo>","list_archive_url":null,"date":"2017-09-01T19:08:35","subject":"Re: [PATCH] thermal: tegra: dereference the pointer after null check","submitter":{"id":26234,"url":"http://patchwork.ozlabs.org/api/people/26234/","name":"Thierry Reding","email":"thierry.reding@gmail.com"},"content":"On Thu, Aug 31, 2017 at 04:52:29PM -0700, Nicolin Chen wrote:\n> The dev pointer is going through a null check after a dereference.\n> So this patch just reverses that.\n> \n> Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>\n> ---\n>  drivers/thermal/tegra/soctherm.c | 4 +++-\n>  1 file changed, 3 insertions(+), 1 deletion(-)\n> \n> diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c\n> index 7d2db23..6718799 100644\n> --- a/drivers/thermal/tegra/soctherm.c\n> +++ b/drivers/thermal/tegra/soctherm.c\n> @@ -478,7 +478,7 @@ static int throttrip_program(struct device *dev,\n>  \t\t\t     struct soctherm_throt_cfg *stc,\n>  \t\t\t     int trip_temp)\n>  {\n> -\tstruct tegra_soctherm *ts = dev_get_drvdata(dev);\n> +\tstruct tegra_soctherm *ts;\n>  \tint temp, cpu_throt, gpu_throt;\n>  \tunsigned int throt;\n>  \tu32 r, reg_off;\n> @@ -486,6 +486,8 @@ static int throttrip_program(struct device *dev,\n>  \tif (!dev || !sg || !stc || !stc->init)\n>  \t\treturn -EINVAL;\n>  \n> +\tts = dev_get_drvdata(dev);\n> +\n>  \ttemp = enforce_temp_range(dev, trip_temp) / ts->soc->thresh_grain;\n>  \n>  \t/* Hardcode LIGHT on LEVEL1 and HEAVY on LEVEL2 */\n\nI don't see a case where dev is ever going to be NULL here. Therefore, I\nthink a better patch would be to just drop the !dev test and leave the\nrest of the code as-is.\n\nThierry","headers":{"Return-Path":"<linux-tegra-owner@vger.kernel.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-tegra-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"ffTq4eUh\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xkTL13whZz9sQl\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat,  2 Sep 2017 05:08:41 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752496AbdIATIk (ORCPT <rfc822;incoming@patchwork.ozlabs.org>);\n\tFri, 1 Sep 2017 15:08:40 -0400","from mail-wm0-f66.google.com ([74.125.82.66]:33566 \"EHLO\n\tmail-wm0-f66.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752490AbdIATIj (ORCPT\n\t<rfc822; linux-tegra@vger.kernel.org>); Fri, 1 Sep 2017 15:08:39 -0400","by mail-wm0-f66.google.com with SMTP id 187so763920wmn.0;\n\tFri, 01 Sep 2017 12:08:38 -0700 (PDT)","from localhost\n\t(p200300E41BD6D60076D02BFFFE273F51.dip0.t-ipconnect.de.\n\t[2003:e4:1bd6:d600:76d0:2bff:fe27:3f51])\n\tby smtp.gmail.com with ESMTPSA id 74sm429525wrk.3.2017.09.01.12.08.36\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tFri, 01 Sep 2017 12:08:36 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20161025;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:in-reply-to:user-agent;\n\tbh=fuz0wDsoseenZlLCPGlt9UDb4isrO2m3M1wY92If8HU=;\n\tb=ffTq4eUhHiDpv+J1qBZ0XP/eDezlSzzWz9z9VGv8+DrOW2ABzJqksBvpAUHIRrS81/\n\tBmRCe76L/ZqewW30yW/x08DNUHyBDxw3SvKe0e8FDAMnIYs3/S6qG2BBl0nua2Wt6W2m\n\t5C4XTjwtDKckZA0VbyhacSYwnZTpDYjk/T4htBmwWt/emEL42SeNh9xWEcTve6T2OS+l\n\t4wRlGg+f+bDQwJLdTqU1m/qbSInKJOjymE/QTMjnjAZXiz28bFM+AMoxyGh7km8RAN5n\n\tr2iKOv8HF4JGQE6N9Ndk1uKE8yx3SCF/jBA6lnRZ6DzDZDFoKDAczObtkT4otNHDuvmY\n\tzbYQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:in-reply-to:user-agent;\n\tbh=fuz0wDsoseenZlLCPGlt9UDb4isrO2m3M1wY92If8HU=;\n\tb=Syrdv8BKizggDliMIpohzZSIyEFOhYHdlQopdFYc40TBKRRmtv0MkmuxKAx5yylSLi\n\tWBOkBdG5g64g2+tN48xC6xOQg1Ne5rltWBNFBLapLFMk+SmaazfyuR62I+mzRbx89nze\n\tAxjYJD5LQfAjh+G8Ch1eWHO9BqSg8/g1d1Px8vEx+7HLukY6ODpxSDoxy1Dib2C7QOtW\n\tn82ibzwyY33Tb+wWjVBBGoZIeuumWDRNHLu5p7ISdp7XW1wzZjw1M0lVRnU/c2Jiravo\n\tmjXv5zYmYScoXf7bJfRdLacapBXa4LWyi6ebVmm0xonLC3IXEZcpyb4u5c0o0LDuiFCz\n\tueGg==","X-Gm-Message-State":"AHPjjUhouGaMCfsz9gfqQdb32hrs3yU/5zLI3KBpMuLifT0e+ms/5W9v\n\tYWTDtAVhkrXCMHcY","X-Google-Smtp-Source":"ADKCNb7OdGpgj7av56J/G9onKZ1z1gq7M2I6uiwPQQfsvmXXoJJByqXpG+Dzz0mhpjUszgJy+QGokw==","X-Received":"by 10.28.74.137 with SMTP id n9mr1059973wmi.110.1504292917536;\n\tFri, 01 Sep 2017 12:08:37 -0700 (PDT)","Date":"Fri, 1 Sep 2017 21:08:35 +0200","From":"Thierry Reding <thierry.reding@gmail.com>","To":"Nicolin Chen <nicoleotsuka@gmail.com>","Cc":"rui.zhang@intel.com, edubezval@gmail.com, jonathanh@nvidia.com,\n\twni@nvidia.com, linux-pm@vger.kernel.org,\n\tlinux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org,\n\tsrikars@nvidia.com","Subject":"Re: [PATCH] thermal: tegra: dereference the pointer after null check","Message-ID":"<20170901190835.GA14011@ulmo>","References":"<1504223549-4152-1-git-send-email-nicoleotsuka@gmail.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"u3/rZRmxL6MmkK24\"","Content-Disposition":"inline","In-Reply-To":"<1504223549-4152-1-git-send-email-nicoleotsuka@gmail.com>","User-Agent":"Mutt/1.8.3 (2017-05-23)","Sender":"linux-tegra-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-tegra.vger.kernel.org>","X-Mailing-List":"linux-tegra@vger.kernel.org"}}]