Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2077616pxb; Mon, 11 Oct 2021 21:13:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4kTyLA+MkE8Lb1Nbq+DS3utrR0vi9W+fWKt8DFonSCfh/xvzC/xsFnn7SPt5BaJ2dKRom X-Received: by 2002:a50:e044:: with SMTP id g4mr46769667edl.46.1634011990306; Mon, 11 Oct 2021 21:13:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634011990; cv=none; d=google.com; s=arc-20160816; b=N2tyL/ZohJKMBL6JLu+N5xXajXG0qbGfziMqJjeZHMToVEHIcYzLVRj9C+k3WzzCzH nsmGfe3YrkTDsE8g8WuPK5ng81QckEml0YLncTKVqlFPomH1pujcffcTU1bDACoOT1Xf ukAYBSrBk4an86/Z9bZ1QYQJqlUlidNNA7C8aHB1QTGxikYy9z48Ncug7g5Vpbe/Q7p7 LfMUNDWtVc9uLpsLEQrqtFxd71PiyZlDj7YydyiblTDaRiCG7PONfro35Crgmf2gStkX zpYlJzNb6Sl/yqJcSeV2jYcTsQdRAFegavocFb/Q5wZBpDtq19DK3bLE2lMcwWJQOAVt W54w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8PINfWRddDPPoULsE0n/xdgtlNqjTbhYGCPqocZwe/Q=; b=Sb2OeJO5Zse/VFPPKRe9YEe5r+8mi/cosdq+yGjeyZQHUvawGDQh6KkI1seVH0SjtU jJruamOXylrP+m+8XrNDMNVuYm2GMrTZfa+gIv6oNDqwb/xJQth+Fr37iMAX0fXR0J6r IOu4Tx6CzOMBmpAhCyx+LQyRqPIZT0T8QhV/Jov0+DNx3WXXkneDtvuD1qTrOiyxRQjj 8MRaY3Z+xnCLAlkgFlRIi08lTrK2ln7K7wHgnbs/iKmuOg9XuU7lIlu40PgZqEvQYDdH aCtlb/WW4l6qe7ROn9kHRzh4xzrozIstyAmxCHk61l9Xzv72yp6srD9nye7xnD5cqLZS Q4lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si13614655eju.701.2021.10.11.21.12.25; Mon, 11 Oct 2021 21:13:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231683AbhJLELK (ORCPT + 99 others); Tue, 12 Oct 2021 00:11:10 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:13721 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbhJLELK (ORCPT ); Tue, 12 Oct 2021 00:11:10 -0400 Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HT2Dz6BLfzWZFj; Tue, 12 Oct 2021 12:07:31 +0800 (CST) Received: from dggpeml500017.china.huawei.com (7.185.36.243) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:08:48 +0800 Received: from huawei.com (10.175.103.91) by dggpeml500017.china.huawei.com (7.185.36.243) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Tue, 12 Oct 2021 12:08:48 +0800 From: Yang Yingliang To: , CC: , Subject: [PATCH v2] rtc: class: check return value when calling dev_set_name() Date: Tue, 12 Oct 2021 12:16:29 +0800 Message-ID: <20211012041629.2504158-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500017.china.huawei.com (7.185.36.243) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I got a null-ptr-deref report when doing fault injection test: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:strcmp+0xc/0x20 Call Trace: __devm_rtc_register_device.cold.7+0x16a/0x2df rv3029_probe+0x4b1/0x770 [rtc_rv3029c2] rv3029_i2c_probe+0x141/0x180 [rtc_rv3029c2] i2c_device_probe+0xa07/0xbb0 really_probe+0x285/0xc30 If dev_set_name() fails, dev_name() is null, it causes null-ptr-deref, we need check the return value of dev_set_name(). Reported-by: Hulk Robot Signed-off-by: Yang Yingliang --- v2: drop some unuseful backtrace in commit message. --- drivers/rtc/class.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index f77bc089eb6b..1f18c39a4b82 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -363,7 +363,9 @@ struct rtc_device *devm_rtc_allocate_device(struct device *dev) rtc->id = id; rtc->dev.parent = dev; - dev_set_name(&rtc->dev, "rtc%d", id); + err = dev_set_name(&rtc->dev, "rtc%d", id); + if (err) + return ERR_PTR(err); err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc); if (err) -- 2.25.1