Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4828274imm; Mon, 11 Jun 2018 20:34:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJHdhV37/6u/mH6RRw93+NiR400iw/7TtneQHddY5UQX8ptIBKHpc+U6PXqpLLUzkkxgj6m X-Received: by 2002:a17:902:7c8b:: with SMTP id y11-v6mr2010631pll.222.1528774480158; Mon, 11 Jun 2018 20:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528774480; cv=none; d=google.com; s=arc-20160816; b=SV2r+p8cmTG8va51xxIL7WIEE2evMbzrdLqmPxIbsS+OZj7An7MQ77iJIpEUstHhNl wRC4F2m99S76QyoRKzsEcXs1eyVbAMjTsobQR0SGdggnzKD4BZTjHsYOHwSYMAeVZ3Fh ELtP5v1NgLvLm99/WUhhARJ2heeaDhLSn8iENyfejprr3P3WpkcgB8jNg9CO4gAVOIPL GAvcA6d/CJfPDAbchmCuzKM8TzqkNd9tUen5WMHhiTsuDRLR+AAaCfLnm/H1Q1xSH7wE 3rco+uSbzsY5XplKgTscW9rWUkNr/QlOi92bAcU1jek62HzmE3dNFVNX22o28FWe0FsH K2dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date:subject:cc:from :dkim-signature:arc-authentication-results; bh=ySuK22Ip9p+jnigLvEr6MmgwCVrgakUH52/VhA/xDE0=; b=U6iC/VTtikknuRUjh3q/yC3WWfCkz3bKJhyUPXNzayszXD09Do5MGTlpexxjnAOU+l cFiF8wq+G48g8yC9jad95TByTDczCaj4CgutLoC0o2yU4vQSDIy9F064Wiw/d7uHfdkY +QYjpn1DLyqSbtPn7QxvYRlLDaLAivNu6PyE/WTJS2lnFFfyvbDbwggjiPJdaxoxUOjp y5ZW1kOM3UiClfyyPRSeMvoqoZVFk0Byh7cuMm7DkOYliPmIBQKijOWHdrm5VCjUt13w Qymvshzjm8Y/LR83FMxcfXmxCDMPJw7HWRHdhRUY2DwW2Hjl2C2zJX4gXeQdfANv1mE0 lKTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SDa3Mo7C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5-v6si29656835pgr.436.2018.06.11.20.34.25; Mon, 11 Jun 2018 20:34:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SDa3Mo7C; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933277AbeFLDdG (ORCPT + 99 others); Mon, 11 Jun 2018 23:33:06 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:38017 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932650AbeFLDdF (ORCPT ); Mon, 11 Jun 2018 23:33:05 -0400 Received: by mail-pl0-f67.google.com with SMTP id b14-v6so13540994pls.5; Mon, 11 Jun 2018 20:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ySuK22Ip9p+jnigLvEr6MmgwCVrgakUH52/VhA/xDE0=; b=SDa3Mo7CH8jYYJScys7SbBcXjEA2mdNg74rmolInalXi1HOtlVLYaTZAMdOk5ZdOaA uXeK8ZFUiwnk1bBG5QE7xCQZ+rMbUnyTeymtcboFWxDi3hmxtMPGcvclrqRTf3K53VSb glgs8BEG0hmJZWMDfB2waETwfAbOrjHESj8yTyVotMOdUVXi7KasCbylOjidR11VsEub x+72u3yYoscc5noGTWxg655KAIZSU2uXVZxrFC8YEKHGAndH/YFoo6yrlULvxQIs84tS T6VD2MIgcsrWJn4LDyz2DhdXvK1jC0x5b32Q7ULqUyjVl8uzFwty/pcAuBPTzMu2Uk2I eQtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ySuK22Ip9p+jnigLvEr6MmgwCVrgakUH52/VhA/xDE0=; b=mBivZT5rGeBIQE3gCXagHHPCMOcsrKstKvfUWqMRwBdjMDOCTJkmx/kL2X8+PDoO8g 0oXOFycXIrntabONv+dnHiiBQmXEoAWqCOcIKEhAyDPA+RzmZg762e2ELMiTesimMvzv I5CzhxuGK/jy4rjY4C2FdDGqC+D3NgM/28bZ6NAg7bSjgVV8swlGvfHM7Nn/rtAsgaB2 0zTiVGz83Yv/enMGKKhGga5J25mVNY654vL2+Wp3Jm6GIwKVu90Re/DcuwAQRwmHdDoY Pb1BgUURXq/RS/EvyqhZfmuODclEKC4uhLt3yXv5ELRAosHHlNB6OsPwlry5TrZkgSo7 TjhQ== X-Gm-Message-State: APt69E1Wu3npx0YrOYvnsDUpfCKGNmYrZzG/H8BIXODBr++aJ6Wb+gx2 f94jnCmT7QN2E2fOxDF3hcQ= X-Received: by 2002:a17:902:23:: with SMTP id 32-v6mr2073000pla.252.1528774384921; Mon, 11 Jun 2018 20:33:04 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id c12-v6sm41219970pfi.177.2018.06.11.20.33.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 20:33:04 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Rudolf Marek , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (w83793) add error handling for i2c_new_dummy Date: Tue, 12 Jun 2018 11:32:59 +0800 Message-Id: <1528774379-38587-1-git-send-email-jiazhouyang09@gmail.com> X-Mailer: git-send-email 2.7.4 To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When i2c_new_dummy fails, the lack of error-handling code may cause unexpected results. This patch adds error-handling code after calling i2c_new_dummy. Signed-off-by: Zhouyang Jia --- drivers/hwmon/w83793.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c index 0af0f62..4aa3a0e 100644 --- a/drivers/hwmon/w83793.c +++ b/drivers/hwmon/w83793.c @@ -1603,8 +1603,15 @@ w83793_detect_subclients(struct i2c_client *client) } tmp = w83793_read_value(client, W83793_REG_I2C_SUBADDR); - if (!(tmp & 0x08)) + if (!(tmp & 0x08)) { data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (tmp & 0x7)); + if (data->lm75[0] == NULL) { + dev_err(&client->dev, + "Failed to allocate I2C device\n"); + err = -ENODEV; + goto ERROR_SC_1; + } + } if (!(tmp & 0x80)) { if ((data->lm75[0] != NULL) && ((tmp & 0x7) == ((tmp >> 4) & 0x7))) { @@ -1616,6 +1623,12 @@ w83793_detect_subclients(struct i2c_client *client) } data->lm75[1] = i2c_new_dummy(adapter, 0x48 + ((tmp >> 4) & 0x7)); + if (data->lm75[1] == NULL) { + dev_err(&client->dev, + "Failed to allocate I2C device\n"); + err = -ENODEV; + goto ERROR_SC_1; + } } return 0; -- 2.7.4