Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7496899ybi; Mon, 22 Jul 2019 14:25:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrI9u148phw1u+scW1MkEGu3PRZ5VeNLdSFmxIZNE7cCiRvW/zSDH+Rs82oYxuv0bg+lJC X-Received: by 2002:a63:c009:: with SMTP id h9mr46098261pgg.166.1563830757284; Mon, 22 Jul 2019 14:25:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563830757; cv=none; d=google.com; s=arc-20160816; b=Mc25A8cAfAKW2tcPDZ5p+yldOZtNQXINtzAoym5JO8Pn+xUKBppUo2nvCGPFlOdg/6 8P3qwpkA4CHgbZhUM5gck3B/dftCzTPrXvfp4uH5yKFD+uiIK9J2/zE+9Mx0/PgLT9KF jlL4DL9YV3nRH5lf4khHCu8cE4qY5qvw1iIhy56wVsmY75fk0sHpTAjbRvckwEUkYV7X J+GiDrs2ntqnIe0fSZUvS2vgUahscC/4UU/+DMebcHkwJW2ElF3tnS22LjVfoPc0bx8H UNVbl/xUz5BPuqYwLjn/AOoW+EB1SgwRB7DhnrzmkJ64nr0rlto1ui8ILlJHF9NvX/ZG QDDQ== 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:date:subject:cc:to:from; bh=sj890l98EZq3pOq2bP6vxlvfYXCN3ElYq7ILFBgj1Cs=; b=nb3qDGuLLNZHTwNg1aV311MvqKa7xg73Lk/x8w8VkXyce93gq8iKMtuxfkomrG7dlw p3AjDaZkcmUiDcQCxnG5IEbL3/Sku3SBpRiRIXW4MrCAT9V/2BVQF+W1m0TLdSNHCjJY 23tYYyPFnkbGDmMB4Krsb22XB5+FeCoHc5Z4ji7eMI3/PQkr6DWqRA3jKJMGJLsY2BxJ vFk22mBj8IQ/8qu0ZCPB9S4lL5KGniSax+jv62fWIZs5kUueZMC/gGp8AGZX2zfDOXuk sNw22keZw9FCoxYuMIugxYFixflj8xO0fOHIjiNJXMx5cLJJWMSBnGjNqyju3z2YtlX1 tWug== 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 4si9520575pfg.55.2019.07.22.14.25.42; Mon, 22 Jul 2019 14:25:57 -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 S1731659AbfGVR1f (ORCPT + 99 others); Mon, 22 Jul 2019 13:27:35 -0400 Received: from sauhun.de ([88.99.104.3]:42428 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731492AbfGVR0e (ORCPT ); Mon, 22 Jul 2019 13:26:34 -0400 Received: from localhost (p54B33E22.dip0.t-ipconnect.de [84.179.62.34]) by pokefinder.org (Postfix) with ESMTPSA id 6D30C4A149A; Mon, 22 Jul 2019 19:26:33 +0200 (CEST) From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] media: ir-kbd-i2c: prevent potential NULL pointer access Date: Mon, 22 Jul 2019 19:26:31 +0200 Message-Id: <20190722172632.4402-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> References: <20190722172632.4402-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Convert to devm_i2c_new_dummy_device() which returns an ERR_PTR and also bail out when failing the validity check. 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