Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4827413imm; Mon, 11 Jun 2018 20:33:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJY9igWmDiP1cugQZ/0LQRY91e/Glpj9VmABbWxAnlg9eR6Ac4X5SX3yJHuGpCKEMQLgTrj X-Received: by 2002:a65:64c6:: with SMTP id t6-v6mr1623939pgv.223.1528774403493; Mon, 11 Jun 2018 20:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528774403; cv=none; d=google.com; s=arc-20160816; b=0G69VN8C/rRcWB2xq5ra5we6lkdPWj/lTbC6FycZeI0Y9agHER2+E+W3cAT9Q6WagM xxN/WO/U7Lod12BFyq6caGnBzRckEn3Gc8aR/C01x5CY56XN5XG025unQQoh45yKeiul G1ti6ilnT8v9SSXQi06kueKgjYqE5QQSNRDgzb2Y/buKY7gum/ZtDFsAE4dKTGukKpoV pDxo+vagK5LaM4hCTc7l5Sz9FemdVjgVMebA+qE2Y3fj46ohgi0xuv0vOU2rcIOOmTB8 rjCtEigaa/Ki7vtdy2bfgCVcGqYL2teJk84r6mM1CWw4eARrLAQvrypoBzu1P5K/ir5n t9QQ== 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=iUn5c6aafdlTZaO1jFoZ5EmuAqZIUkHskaPyuidu2L0=; b=YMvcx4cbn8CowyxNqrM4qJQVB0UKd69dwpFZf0DCNm4bAOl61SVFRhXmUm8GReGctE gHm3UD5K8dK+MFKEpPZgOPeRoWAatgZv0/xn7f8fVWhCyGSUp5roLOtzrUG9JTffauSZ x9ZhCdxfx6NXMcadNait0GNCBxWH+CS+q2j6VY5Y5/mfhdafDCK+12ZiU0tkcpGUcqD8 2Y383y1YV/3H54QI9M8wmSgCl5KocpK7SgaHkkDXwOXY8Eogvrs43isMia1sNJjHULk1 StMPdEbUARPT2/OTXag+XXwWwS1r9X9tLZGk+gSxBgRH3ovlRTdOklsTgdbN42dbMQyg pBtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gR+Of7qE; 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 cc7-v6si6455348plb.5.2018.06.11.20.33.09; Mon, 11 Jun 2018 20:33:23 -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=gR+Of7qE; 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 S933045AbeFLDbh (ORCPT + 99 others); Mon, 11 Jun 2018 23:31:37 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:42049 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932650AbeFLDbg (ORCPT ); Mon, 11 Jun 2018 23:31:36 -0400 Received: by mail-pf0-f195.google.com with SMTP id w7-v6so11320401pfn.9; Mon, 11 Jun 2018 20:31:35 -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=iUn5c6aafdlTZaO1jFoZ5EmuAqZIUkHskaPyuidu2L0=; b=gR+Of7qEBtT/VJuEVqqEsimWdBmy7dwFhuunhWUfteQljGLnBaqV3kOSmyFNVNIPLx 3ukulCkUJsiXWuYa5iuQxXwIQjVZsKGX2U4Dt27hdlEr9kVe7jS7wT+o1q+m7KhaSF0n +jGKYtTlgTnnv/zqKx/5n5vwv7Eh3kfpTOrpDagIytoekh13T1mpvNP2YeLcUJkCmyEG M04o0wWdb8Cp3bKTSRCIVBpZOWobFP2lcqGFot1o9VXRairGjMENJq3TeQR2TD+hrMba 0+sOOgdGKx6NIdMF0reHYirISTYrKdcHClOzkUZAKnG1wDhnSaZU2jLlRuL7MNxAirhI 1PFg== 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=iUn5c6aafdlTZaO1jFoZ5EmuAqZIUkHskaPyuidu2L0=; b=F3Z8qmjf62eOdII9p99+77GBSpNAAhY/mfr46jWP5W67aYi9i8WDPap+UArYMZM8yR AB1R4wFOmw0QumslPhHjcnodse2grGwuGx73picX9Lzm5MWKXbbjEjWM3A/eMC1ommDG EWSF+S4xPclczI4qYXFxQUKgImNBADb5YJhBjsNPWknzmI03GxIShmUEU0Lfsd4r+35v TwL9TzjfPSW7oLVSRS24vgKDiIWPpPo0UjXDYLWVXH/1tNZZlOQQmlfDNpk2o59YoqRB PmZ1fnykrg7Yn8nGm+0leGB6ENdbyeLHYsPiy8ozrEwR3KOul5q1vmv/78Wxd6lDkUYr +JuQ== X-Gm-Message-State: APt69E1ENDXX6M55f9BJlM5qDGpKPYmHviD1XuKtp+hSCKZ2lBNjwl+D 8ASmS/Sn4xIWo8YhRjw0CWSusyICsUA= X-Received: by 2002:a65:6101:: with SMTP id z1-v6mr1614989pgu.282.1528774295711; Mon, 11 Jun 2018 20:31:35 -0700 (PDT) Received: from localhost ([103.88.46.82]) by smtp.gmail.com with ESMTPSA id l11-v6sm7280641pgp.56.2018.06.11.20.31.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 20:31:35 -0700 (PDT) From: Zhouyang Jia Cc: Zhouyang Jia , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon: (w83792d) add error handling for i2c_new_dummy Date: Tue, 12 Jun 2018 11:31:28 +0800 Message-Id: <1528774289-38443-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/w83792d.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c index 76aa39e..2c168c5 100644 --- a/drivers/hwmon/w83792d.c +++ b/drivers/hwmon/w83792d.c @@ -961,8 +961,15 @@ w83792d_detect_subclients(struct i2c_client *new_client) } val = w83792d_read_value(new_client, W83792D_REG_I2C_SUBADDR); - if (!(val & 0x08)) + if (!(val & 0x08)) { data->lm75[0] = i2c_new_dummy(adapter, 0x48 + (val & 0x7)); + if (data->lm75[0] == NULL) { + dev_err(&new_client->dev, + "Failed to allocate I2C device\n"); + err = -ENODEV; + goto ERROR_SC_1; + } + } if (!(val & 0x80)) { if ((data->lm75[0] != NULL) && ((val & 0x7) == ((val >> 4) & 0x7))) { @@ -974,6 +981,12 @@ w83792d_detect_subclients(struct i2c_client *new_client) } data->lm75[1] = i2c_new_dummy(adapter, 0x48 + ((val >> 4) & 0x7)); + if (data->lm75[1] == NULL) { + dev_err(&new_client->dev, + "Failed to allocate I2C device\n"); + err = -ENODEV; + goto ERROR_SC_1; + } } return 0; -- 2.7.4