Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp2249551img; Sun, 24 Mar 2019 03:49:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqz51z2zzJFC3B+pcMysmd6KybFyRaISziHRus5iwFWjTyisiwkZH3NUSJ0qlkty/kU/POsS X-Received: by 2002:a65:49c4:: with SMTP id t4mr18005193pgs.421.1553424598197; Sun, 24 Mar 2019 03:49:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553424598; cv=none; d=google.com; s=arc-20160816; b=SuW+k2NlLhsBGNwHyf94CFAou8XiAFlNpAkbJtRW/8I4InI/KEM0bbKxt6dhy9RvNV gO2YjTvh/4TbiOnOLkjuhm6GnuEHdgErksRPQr06giP+AuqN7wXB9HwhiLJ2xjmkaOmG hm9ASTl2RZ7kINe8jgvMmmySgoS7gwD0IA+MSZ2loLSYf1KquZCjYrC3BJHOs1Ld7YkQ R1A2BI2mE2XitLJ1Oc0MUl3/knJXJve5qp5dO4MFlzaOO9U3Ne4n7cmOcOg4InhvKEmc 08fTI5AAduIeqKhF1x4WBUK26tvOslXeJmmZfUGQoOt2+S2NfX5a6BxmjIydhje0MLi3 plJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=tw1aR15Ydm3CuEvkKOXm4pFrw/19BUqB1eWDaiDo/t4=; b=Dg706ZS3Fvx1/4/0Y21rFSyOxCXkYyoKUpj9boeiIDBF1T/0bUyCNJS/udkAzQvA5V LNZ1eyxfTvAwOL0djKjFTU+7WtEf35CiuP8ONe5/kv82lkY7ey2YAEKtsf7xt1i+EEVL +soeGJNM29hWC/sbdYeQtATvcEwPlax3/2dUUjuqKahjnmILJxB+9A9UHRN1OCQ34Lmu +XgO01Dh8Fr+lrjEqpIRCMGIVk5CC0F98ET3ktRENfdOICzDtIsRzf0zh3kEWZpV8tlQ Ujsveu0J45lgx3YEdiIXSYIBIe76pnvlerN0Zf5NkngaY5G0aWvtXOY0TYe4+6IKXn2b NmpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FmSox5H3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u22si3223689pga.129.2019.03.24.03.49.41; Sun, 24 Mar 2019 03:49:58 -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=pass header.i=@kernel.org header.s=default header.b=FmSox5H3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbfCXKtC (ORCPT + 99 others); Sun, 24 Mar 2019 06:49:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:49936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726173AbfCXKtB (ORCPT ); Sun, 24 Mar 2019 06:49:01 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 72D9321B24; Sun, 24 Mar 2019 10:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553424541; bh=/DFt5fU/vxRKsb8S7KrQ2hYgKHDtrEfUPgD2GgReHbM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FmSox5H3xDWqzQ1jOPaDK/A+f4VsSNzgPtqAEsKqCFTyEjoMVzoteAYDSptUkcYAQ trp1G/eRakBVTIjLswqs9/4252YAbqd8AKVXHN3c6ecBj1RlQ3JF4FRJ2ZG+fsVPNl F39VT03WprLKJuKHVPMC9dNQunl+og1vpT1pHKfQ= Date: Sun, 24 Mar 2019 10:48:56 +0000 From: Jonathan Cameron To: Kangjie Lu Cc: pakki001@umn.edu, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] iio: hmc5843: fix potential NULL pointer dereferences Message-ID: <20190324104856.3883150b@archlinux> In-Reply-To: <20190316220836.25092-1-kjlu@umn.edu> References: <20190316151912.4a7ea87d@archlinux> <20190316220836.25092-1-kjlu@umn.edu> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 16 Mar 2019 17:08:33 -0500 Kangjie Lu wrote: > devm_regmap_init_i2c may fail and return NULL. The fix returns > the error when it fails. > > Signed-off-by: Kangjie Lu Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks. Jonathan > --- > V2: fix the two together > --- > drivers/iio/magnetometer/hmc5843_i2c.c | 7 ++++++- > drivers/iio/magnetometer/hmc5843_spi.c | 7 ++++++- > 2 files changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c > index 3de7f4426ac4..86abba5827a2 100644 > --- a/drivers/iio/magnetometer/hmc5843_i2c.c > +++ b/drivers/iio/magnetometer/hmc5843_i2c.c > @@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = { > static int hmc5843_i2c_probe(struct i2c_client *cli, > const struct i2c_device_id *id) > { > + struct regmap *regmap = devm_regmap_init_i2c(cli, > + &hmc5843_i2c_regmap_config); > + if (IS_ERR(regmap)) > + return PTR_ERR(regmap); > + > return hmc5843_common_probe(&cli->dev, > - devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config), > + regmap, > id->driver_data, id->name); > } > > diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c > index 535f03a70d63..8355713651d4 100644 > --- a/drivers/iio/magnetometer/hmc5843_spi.c > +++ b/drivers/iio/magnetometer/hmc5843_spi.c > @@ -58,6 +58,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = { > static int hmc5843_spi_probe(struct spi_device *spi) > { > int ret; > + struct regmap *regmap; > const struct spi_device_id *id = spi_get_device_id(spi); > > spi->mode = SPI_MODE_3; > @@ -67,8 +68,12 @@ static int hmc5843_spi_probe(struct spi_device *spi) > if (ret) > return ret; > > + regmap = devm_regmap_init(spi, &hmc5843_spi_regmap_config); > + if (IS_ERR(regmap)) > + return PTR_ERR(devm_regmap); > + > return hmc5843_common_probe(&spi->dev, > - devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config), > + regmap, > id->driver_data, id->name); > } >