Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1219768imi; Fri, 22 Jul 2022 21:52:37 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ud+VZ4hP9I4sauP2qpwOriSM95fGOjNKbno7IbSZfP2n/MFvMmBfr10gtSINwRnXUyuWmf X-Received: by 2002:a17:903:245:b0:16b:9c49:6b1c with SMTP id j5-20020a170903024500b0016b9c496b1cmr2640021plh.153.1658551957557; Fri, 22 Jul 2022 21:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658551957; cv=none; d=google.com; s=arc-20160816; b=r2Kp3JTTmi9wePBG5nVo1vZtYTmuC1HsUtbiVmsOR/d3Pb/jNxvuq2RF4wle7hTOWD zW0mOZLeLD5Q5Szu0FfOEqlU1qfWKcbif8Ukj2FXQCf2/LpeAHRL9HlS6UpU63nVOVqk IE/DCabRD1JifnddSW4Zfbm2caN9puZpJAbHBeLHLJaaQYSEmDGak5vZyHnKNBlHNTzB ZBmq3q1sTRRCDNhBivFIMTZ6xAHPjaeZcwyIeoO0aN/J3bkJJ4QIp+7OHwziZlV7g93X M+ZNxLYPKxwdQYIqXbOni441IPR0qAaSYm5AV2+DPUCTLzCglExRDCAYbRro0YaP4J7g 8qwQ== 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:dkim-signature; bh=uXlb1r3BbJdtgryVnq7yMNYfh6mt8p4E1um7vBRzrRs=; b=ZdxJjJz3RT0d+MECIlR5/1mBrFmRPb8R8DcUdsbeez8Ujt4cZsfoaIlxGzTeS9IEUY Tj1vvTeyDSQaa7Lo3R/uB2d8xU1ZDamwgLM9AMangUJDoG6my2k/uOp5sj+uux9f8+SR 00TUWLC3oqlAUZdjfXhJIu5/uyX5rr03RZ6Oek1L0GqZytyPdg82eslqciSyHJo1ydy4 oAvkeTib31D+qLig9xADa2LibpZ/O8xSD0ozbs1nb6yX3Flo3H4HA8/TRUwPyGs1YC1L Oz0dpMI8i2IFI8Ij9ECEu2rKfTMLqdwJkfrJpmp7SSz72pLApvIhxsTiZffbSg0iG/Vt vQhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jrVHDzAI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a170903024e00b0016413dbc6a4si9107945plh.429.2022.07.22.21.52.22; Fri, 22 Jul 2022 21:52:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jrVHDzAI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236792AbiGWEd3 (ORCPT + 99 others); Sat, 23 Jul 2022 00:33:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiGWEd2 (ORCPT ); Sat, 23 Jul 2022 00:33:28 -0400 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 17D3BBA4F0; Fri, 22 Jul 2022 21:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=uXlb1 r3BbJdtgryVnq7yMNYfh6mt8p4E1um7vBRzrRs=; b=jrVHDzAIIIvcEoC6nuvpW 4jmC5YBYAG4erNe21gAUefQ2zG9mcO5scJz6oqgUc0Kx9SXlj/1opoDJg8KLelcX 4ERMHuZk9HObyYWKTAmM3wepaB/ypsCQGsePLtkDIOFCeatPQx+HnfND/4iXbp4w Ko7y4mrxujgKcQn5hj7WBU= Received: from localhost.localdomain (unknown [123.58.221.99]) by smtp3 (Coremail) with SMTP id G9xpCgBnBZfeedtiEC0yQw--.2963S2; Sat, 23 Jul 2022 12:32:32 +0800 (CST) From: williamsukatube@163.com To: bence98@sch.bme.hu, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: William Dean , Hacash Robot Subject: [PATCH] i2c: cp2615: check the return value of kzalloc() Date: Sat, 23 Jul 2022 12:32:29 +0800 Message-Id: <20220723043229.2953386-1-williamsukatube@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: G9xpCgBnBZfeedtiEC0yQw--.2963S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WF48Kr1xXr47uF47Gry7trb_yoW8Ww13pF 1fCF4DCr4Uta42gr4DZry8XFySgw1rGF9rJrW7tasxZryxZr95Jw1jgr1rZFWrAFWUKr12 qayDt3WxuF1kur7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bwT5LUUUUU= X-Originating-IP: [123.58.221.99] X-CM-SenderInfo: xzlozx5dpv3yxdwxuvi6rwjhhfrp/1tbiNwBHg1WBo2wCAQAAsr X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: William Dean kzalloc() is a memory allocation function which can return NULL when some internal memory errors happen. So it is better to check the return value of it to prevent potential wrong memory access or memory leak. Fixes: 4a7695429eade ("i2c: cp2615: add i2c driver for Silicon Labs' CP2615 Digital Audio Bridge") Reported-by: Hacash Robot Signed-off-by: William Dean --- drivers/i2c/busses/i2c-cp2615.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-cp2615.c b/drivers/i2c/busses/i2c-cp2615.c index 3ded28632e4c..7c9403346615 100644 --- a/drivers/i2c/busses/i2c-cp2615.c +++ b/drivers/i2c/busses/i2c-cp2615.c @@ -171,11 +171,17 @@ cp2615_i2c_recv(struct usb_interface *usbif, unsigned char tag, void *buf) /* Checks if the IOP is functional by querying the part's ID */ static int cp2615_check_iop(struct usb_interface *usbif) { - struct cp2615_iop_msg *msg = kzalloc(sizeof(*msg), GFP_KERNEL); - struct cp2615_iop_accessory_info *info = (struct cp2615_iop_accessory_info *)&msg->data; + struct cp2615_iop_msg *msg; + struct cp2615_iop_accessory_info *info; struct usb_device *usbdev = interface_to_usbdev(usbif); - int res = cp2615_init_iop_msg(msg, iop_GetAccessoryInfo, NULL, 0); + int res; + + msg = kzalloc(sizeof(*msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + info = (struct cp2615_iop_accessory_info *)&msg->data; + res = cp2615_init_iop_msg(msg, iop_GetAccessoryInfo, NULL, 0); if (res) goto out; -- 2.25.1