From patchwork Mon Apr 16 17:08:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ahsan Hussain X-Patchwork-Id: 10343535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AC509601D7 for ; Mon, 16 Apr 2018 17:08:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D10328826 for ; Mon, 16 Apr 2018 17:08:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91ACD2882B; Mon, 16 Apr 2018 17:08:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B7DE28826 for ; Mon, 16 Apr 2018 17:08:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753125AbeDPRI3 (ORCPT ); Mon, 16 Apr 2018 13:08:29 -0400 Received: from relay1.mentorg.com ([192.94.38.131]:53364 "EHLO relay1.mentorg.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753099AbeDPRI2 (ORCPT ); Mon, 16 Apr 2018 13:08:28 -0400 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-02.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1f87cA-0001Ln-K3 from Ahsan_Hussain@mentor.com ; Mon, 16 Apr 2018 10:08:26 -0700 Received: from [137.202.156.247] (137.202.0.87) by svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Mon, 16 Apr 2018 18:08:21 +0100 Subject: [PATCH 1/1] hwmon: (ina2xx) initialize mutex before locking CC: , , , , chombour , ahsann , From: Ahsan Hussain Organization: Mentor Graphics Message-ID: Date: Mon, 16 Apr 2018 22:08:19 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.87] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To: unlisted-recipients:; (no To-header on input) Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Upstream commit 8d008c0c ("hwmon: (ina2xx) Make calibration register value fixed") makes ina2xx_set_shunt() call mutex_lock on an un-initialized mutex. Initialize it prior so we don't get a NULL pointer dereference error Signed-off-by: Ahsan Hussain --- drivers/hwmon/ina2xx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) } - mutex_init(&data->config_lock); - data->groups[group++] = &ina2xx_group; if (id->driver_data == ina226) data->groups[group++] = &ina226_group; diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index a629f7c..1304f01 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -457,6 +457,8 @@ static int ina2xx_probe(struct i2c_client *client, val = INA2XX_RSHUNT_DEFAULT; } + mutex_init(&data->config_lock); + ina2xx_set_shunt(data, val); ina2xx_regmap_config.max_register = data->config->registers; @@ -473,8 +475,6 @@ static int ina2xx_probe(struct i2c_client *client, return -ENODEV;