Message ID | 20240116083847.89934-1-chentao@kylinos.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-27132-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp123363dye; Tue, 16 Jan 2024 00:40:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1L/qTHqFHjEskO31psxXqSGayiS7yuA5YLRMtgVsSmCMuFNbLpUo8p6qqzTkliSB2TyhW X-Received: by 2002:a17:90a:9d8a:b0:28d:29ce:155e with SMTP id k10-20020a17090a9d8a00b0028d29ce155emr2953292pjp.36.1705394411237; Tue, 16 Jan 2024 00:40:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705394411; cv=none; d=google.com; s=arc-20160816; b=vhkrkx1q4uoT/cVdjzT7bMU7diy/dOp0OTOWiiTcrw9M1pxIGswv5lfJ+79v2nQ73f nl6jgVOzXoPgU2eX2/K8sXFytn5VKVk3OjCSyAvT4sziGBK4yZVqBKiuNDj04KRAnDR5 QRk/U1JnmbfSMSbANfXW0siJIlejGAVKFZU29fKThEzyYQOnZ8y1pYtVKemwK+0Y/sUY UQ3su4s3tri6Jziv6W+mwhDxY0Xz2UE5jozI7t4jL//cptXwTwIN1JNMODJpLDQA48ku vmDuTFO7oMtHn4w/RT6NPyycWfq9nYHupzIzkUD0WnrNIJXBNxPuC7mDBj3o4iZEi31i GMlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=M6D9n6zV94cZ++9wo8qCtuGPgzRuA01g6F4fYvQt+FE=; fh=tS6/lUiSky2Mhtqt7lDz9D/xarJ+F5reP1Ov1LWumUs=; b=gZ5opPxo3WhsYcV5Zvnr/abSgAHcCsE5Aq3dfdJ8otcaDwdocpk0YN7xtpefA8/e2q tUaVoIUVJtarRyG7njsjmHZNcavWPcKCcCWWMGONmYgBjRErBHauH2isXVBZlgNanhxQ PfjNdjt1Yyc+TnJDhl69jm1j5Vp7MJHawoFVTYrw1OgQuohC4WcsUpZPsaEC4TdXTNn6 n4mLluIV4HC2pLjUteCY6JEkjoZye7KjxoaoCX4mXvpTEctbtF9AE6l7h0qFSSdRnl8w uFEOhXoD0LL6lQ8KWCPyEIsc8nDB3KtxJJKYdUhtuwfLXTbyJIKAhGZxZ7cDOCMvizYD drhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27132-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e3-20020a170902b78300b001d5d57cc1d8si2722269pls.252.2024.01.16.00.40.10 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 00:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27132-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D8F27B22E7E for <ouuuleilei@gmail.com>; Tue, 16 Jan 2024 08:39:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8B10125BF; Tue, 16 Jan 2024 08:39:18 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4D0D11C8B; Tue, 16 Jan 2024 08:39:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 9e26d15b068842508cea8914b7d8260f-20240116 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:c3d94d1a-6232-43f3-9c7d-02add46f3c88,IP:20, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:30 X-CID-INFO: VERSION:1.1.35,REQID:c3d94d1a-6232-43f3-9c7d-02add46f3c88,IP:20,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:30 X-CID-META: VersionHash:5d391d7,CLOUDID:c7ac4d8e-e2c0-40b0-a8fe-7c7e47299109,B ulkID:240116163853GJBD7274,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:5,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL :0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 9e26d15b068842508cea8914b7d8260f-20240116 Received: from mail.kylinos.cn [(39.156.73.10)] by mailgw (envelope-from <chentao@kylinos.cn>) (Generic MTA) with ESMTP id 222917768; Tue, 16 Jan 2024 16:38:50 +0800 Received: from mail.kylinos.cn (localhost [127.0.0.1]) by mail.kylinos.cn (NSMail) with SMTP id BF4A2E000EB9; Tue, 16 Jan 2024 16:38:50 +0800 (CST) X-ns-mid: postfix-65A6409A-58652291 Received: from kernel.. (unknown [172.20.15.234]) by mail.kylinos.cn (NSMail) with ESMTPA id E5E41E000EB9; Tue, 16 Jan 2024 16:38:49 +0800 (CST) From: Kunwu Chan <chentao@kylinos.cn> To: dmitry.torokhov@gmail.com, aduggan@synaptics.com, cheiny@synaptics.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan <chentao@kylinos.cn> Subject: [PATCH] Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe Date: Tue, 16 Jan 2024 16:38:47 +0800 Message-Id: <20240116083847.89934-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788235650243454932 X-GMAIL-MSGID: 1788235650243454932 |
Series |
Input: synaptics-rmi4: Fix NULL pointer dereference in rmi_driver_probe
|
|
Commit Message
Kunwu Chan
Jan. 16, 2024, 8:38 a.m. UTC
devm_kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.
Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI4 devices")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
drivers/input/rmi4/rmi_driver.c | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On Tue, Jan 16, 2024 at 04:38:47PM +0800, Kunwu Chan wrote: > devm_kasprintf() returns a pointer to dynamically allocated memory > which can be NULL upon failure. Ensure the allocation was successful > by checking the pointer validity. It is perfectly valid to not set "input->phys" and leave it at NULL. So while I agree that having error handling is good I do not believe there's chance for NULL pointer dereference, so please adjust your patch title. > > Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI4 devices") > Signed-off-by: Kunwu Chan <chentao@kylinos.cn> > --- > drivers/input/rmi4/rmi_driver.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c > index 258d5fe3d395..d3a601ff51e6 100644 > --- a/drivers/input/rmi4/rmi_driver.c > +++ b/drivers/input/rmi4/rmi_driver.c > @@ -1197,6 +1197,12 @@ static int rmi_driver_probe(struct device *dev) > rmi_driver_set_input_params(rmi_dev, data->input); > data->input->phys = devm_kasprintf(dev, GFP_KERNEL, > "%s/input0", dev_name(dev)); > + if (!data->input->phys) { > + dev_err(dev, "%s: Failed to allocate memory.\n", No need to log the error here, memory allocation will already log the failure. Thanks.
On 2024/1/17 03:11, Dmitry Torokhov wrote: > On Tue, Jan 16, 2024 at 04:38:47PM +0800, Kunwu Chan wrote: >> devm_kasprintf() returns a pointer to dynamically allocated memory >> which can be NULL upon failure. Ensure the allocation was successful >> by checking the pointer validity. > > It is perfectly valid to not set "input->phys" and leave it at NULL. So > while I agree that having error handling is good I do not believe > there's chance for NULL pointer dereference, so please adjust your patch > title. Thanks for your suggestions. I'll change patch title to "Input: synaptics-rmi4: Add a null pointer check to the rmi_driver_probe". >> >> Fixes: 2b6a321da9a2 ("Input: synaptics-rmi4 - add support for Synaptics RMI4 devices") >> Signed-off-by: Kunwu Chan <chentao@kylinos.cn> >> --- >> drivers/input/rmi4/rmi_driver.c | 6 ++++++ >> 1 file changed, 6 insertions(+) >> >> diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c >> index 258d5fe3d395..d3a601ff51e6 100644 >> --- a/drivers/input/rmi4/rmi_driver.c >> +++ b/drivers/input/rmi4/rmi_driver.c >> @@ -1197,6 +1197,12 @@ static int rmi_driver_probe(struct device *dev) >> rmi_driver_set_input_params(rmi_dev, data->input); >> data->input->phys = devm_kasprintf(dev, GFP_KERNEL, >> "%s/input0", dev_name(dev)); >> + if (!data->input->phys) { >> + dev_err(dev, "%s: Failed to allocate memory.\n", > > No need to log the error here, memory allocation will already log the > failure. Thanks, I'll remove the dev_err. > > Thanks. >
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 258d5fe3d395..d3a601ff51e6 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -1197,6 +1197,12 @@ static int rmi_driver_probe(struct device *dev) rmi_driver_set_input_params(rmi_dev, data->input); data->input->phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input0", dev_name(dev)); + if (!data->input->phys) { + dev_err(dev, "%s: Failed to allocate memory.\n", + __func__); + retval = -ENOMEM; + goto err; + } } retval = rmi_init_functions(data);