Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10421021ybi; Wed, 24 Jul 2019 22:55:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRPiaf6DbUkHNozrxN4UFxLEjtWmSDCCfx22Qv8KaHkuFCD4veVQJEyTHsdGRt3FVS0Mgz X-Received: by 2002:a17:902:aa41:: with SMTP id c1mr88699929plr.201.1564034140057; Wed, 24 Jul 2019 22:55:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034140; cv=none; d=google.com; s=arc-20160816; b=yyqGBOM3X4EcTozA5Na1YzS0BadZjiXfADOa8DiJ1Jn6e8HD6n0bYDo8ZGpcxUIGua 93lNzMuXZ2+rs4sz63JXF/whBNi68RQ8WOZqaT0YV6P2XDdvPF6nxL+dx++sL31dJrNu 2+cPJ9E1DgPb5AgIY0Y3H3EKW9A1Cjf29rCq0zXfStgN2DX9v5Uja8EzBe9mvG/5zFZp 6Bsth7jROIVjf1M/lMv5SArswNiebSHZKMp/UgCC2AKPBSgnGDeVtTPzzFv2DmnoR3aQ 80iOCqrMV4G850MYYawncAGeCJwtRA2GfxJMj/2WTKvWz7HZvPWRyErkirEZ/4pr43CB lixA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=3tq3HeDeboIo0IOdOfbdhGfIs19KsdKVJEg+rPFTcys=; b=aTAXOxn1oAX8CgzY77g81lkLckG9Jf3ilgE2UoupvLqOF8MaOBNaaOpDC2B6xlaikt DCTA2cX9fJ3/WY4Cyl9E9k/PNrcrl4ySRQhi6EhmkfCx7lMn96Fc3DC3F54IH///vgaF J2zo202TzVHHbwcKV/SM6TNZFzYYebYw/V/dRumXWPaO+MPK9d0uuiFqDjjgMZwtWhC/ EIh5SVzaImUYynokVfA8oF6XpJef83HBB27f8uY2Fu6J8/TevxuknbS2z/FFUP9ig1dB FZqfzVppRIax1JOAQbe1vK1K0RANTjPUy4Ysl4AyRPljlw4LNQDt7Gv8uXX+oeVf1WkX vMKg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3si15513516plx.344.2019.07.24.22.55.25; Wed, 24 Jul 2019 22:55: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390482AbfGYFMF (ORCPT + 99 others); Thu, 25 Jul 2019 01:12:05 -0400 Received: from gofer.mess.org ([88.97.38.141]:34441 "EHLO gofer.mess.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390362AbfGYFME (ORCPT ); Thu, 25 Jul 2019 01:12:04 -0400 Received: by gofer.mess.org (Postfix, from userid 1000) id AFB1C60474; Thu, 25 Jul 2019 06:12:02 +0100 (BST) Date: Thu, 25 Jul 2019 06:12:02 +0100 From: Sean Young To: Wolfram Sang Cc: linux-i2c@vger.kernel.org, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] media: ir-kbd-i2c: prevent potential NULL pointer access Message-ID: <20190725051202.o47mz4unbn63z6uk@gofer.mess.org> References: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> <20190722172632.4402-2-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190722172632.4402-2-wsa+renesas@sang-engineering.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 22, 2019 at 07:26:31PM +0200, Wolfram Sang wrote: > i2c_new_dummy() can fail returning a NULL pointer. The code does not > bail out in this case and the returned pointer is blindly used. I don't see how. The existing code tries to set up the tx part; if i2c_new_dummy() return NULL then the rcdev is registered without tx, and tx_c is never used. > Convert > to devm_i2c_new_dummy_device() which returns an ERR_PTR and also bail > out when failing the validity check. Possibly I was being overly cautious with not bailing out if tx can't be registered; moving to devm is probably a good idea. However the commit message is misleading, because the existing code has no NULL pointer access. Sean > > Signed-off-by: Wolfram Sang > --- > drivers/media/i2c/ir-kbd-i2c.c | 13 +++++-------- > 1 file changed, 5 insertions(+), 8 deletions(-) > > diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c > index 876d7587a1da..f46717052efc 100644 > --- a/drivers/media/i2c/ir-kbd-i2c.c > +++ b/drivers/media/i2c/ir-kbd-i2c.c > @@ -885,9 +885,12 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) > INIT_DELAYED_WORK(&ir->work, ir_work); > > if (probe_tx) { > - ir->tx_c = i2c_new_dummy(client->adapter, 0x70); > - if (!ir->tx_c) { > + ir->tx_c = devm_i2c_new_dummy_device(&client->dev, > + client->adapter, 0x70); > + if (IS_ERR(ir->tx_c)) { > dev_err(&client->dev, "failed to setup tx i2c address"); > + err = PTR_ERR(ir->tx_c); > + goto err_out_free; > } else if (!zilog_init(ir)) { > ir->carrier = 38000; > ir->duty_cycle = 40; > @@ -904,9 +907,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) > return 0; > > err_out_free: > - if (ir->tx_c) > - i2c_unregister_device(ir->tx_c); > - > /* Only frees rc if it were allocated internally */ > rc_free_device(rc); > return err; > @@ -919,9 +919,6 @@ static int ir_remove(struct i2c_client *client) > /* kill outstanding polls */ > cancel_delayed_work_sync(&ir->work); > > - if (ir->tx_c) > - i2c_unregister_device(ir->tx_c); > - > /* unregister device */ > rc_unregister_device(ir->rc); > > -- > 2.20.1