Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3702502pxb; Mon, 24 Jan 2022 15:48:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJw19zDHBngbUPJcJhxcZmusbMZdIsyJ5ZeD50Us94CbDogkXS8wFeBWtVLJJC0EjgNl2GM1 X-Received: by 2002:a17:902:7009:b0:14b:ce9:80b0 with SMTP id y9-20020a170902700900b0014b0ce980b0mr16173403plk.97.1643068120249; Mon, 24 Jan 2022 15:48:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068120; cv=none; d=google.com; s=arc-20160816; b=jbEOXX7gmKg2/DmDTaYUmzkl+hHeuItVh2P1jxnlO/GZzRpyYJ3btq/OCjK50MiBL9 nnL7rEylg40EyXJCWHmoRjb1FhJhlsrMjVZ82uoxzBAn/E8ZHWr1Hfa6CR2tZJ0QiEpI FR/c32UBwoIZ66BoipbnA0gCsQL3FI+IbNseRV0ISJMxHVjd7kvqdnkru3NWdeBv4rSE 0Zx4ccvp+eSYKS02/Kll9TS3/1oJVSuuiLKzWg3YdMDakmOut7nfQBewSNSwGoCb5IMH pA7S9//iHtmwr7V4DpuaX92m30O3iXedOYeIoYwBRRNAR9Qj3HkgS0eUEes6oOtFYxNi om9g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nYhMehsCNDSUcUrmaJ38U43+zIX9dWHHqkdkU75YFwo=; b=dftTb5uehFVhDPsxhHUsx9ri2ToPiP6lSH3yMXBkHvL0eru6Ym80uo022+oi+obDsV ewOKipOZcsxADCIU7ogmNgfIFH/KnEWRRwrhqzFoU1WMG+iem1JdXkL9Xsnr8op1I6kH FTQs3h3ORAf8PIvqQeomxOo6vFDqurl1l6Lt/qUBw5qksw53K75/VVCymiu9Lmk1tD0M P+/T8nr2HmaKPT2FT2wX3juq5t2MlfGOLVMqWSA3igOol6tOGa8LIyaVn6AJpCDLyyaE IGfheTciL8dsFkDB9ypGSujTaJ/cERmaTUtFMbV/teRdC7hT2GuvxD/Wetbl1DWYgYYH ijbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SJ/MVyMV"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j12si15174297pfu.247.2022.01.24.15.48.28; Mon, 24 Jan 2022 15:48:40 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="SJ/MVyMV"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2361622AbiAXXke (ORCPT + 99 others); Mon, 24 Jan 2022 18:40:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1841133AbiAXW5l (ORCPT ); Mon, 24 Jan 2022 17:57:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D61DC0401FB; Mon, 24 Jan 2022 13:12:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 19EB5B8123A; Mon, 24 Jan 2022 21:12:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A3F8C340E5; Mon, 24 Jan 2022 21:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058729; bh=I7z8eH5nCgiPqJded8zsJpYyxh4knj/NV0JID3n0uKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJ/MVyMVepdG/TnAmcviKoMpXLPIPC93BluJFdJUOjDfVMrpNINgAIHdMd3FrnkYO z3luv+Eja5lNlyidpNjOxM2+oIINepA2tD5UETncyUXlZoPJgcsBAKapdQkt7cuuhY uQ7dC+YMb3SJvMUsH28FiQe9hEgiz+7YwuXvPLuI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Elder , Jiasheng Jiang , Sasha Levin Subject: [PATCH 5.16 0384/1039] staging: greybus: audio: Check null pointer Date: Mon, 24 Jan 2022 19:36:13 +0100 Message-Id: <20220124184138.217453976@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiasheng Jiang [ Upstream commit 2e81948177d769106754085c3e03534e6cc1f623 ] As the possible alloc failure of devm_kcalloc(), it could return null pointer. Therefore, 'strings' should be checked and return NULL if alloc fails to prevent the dereference of the NULL pointer. Also, the caller should also deal with the return value of the gb_generate_enum_strings() and return -ENOMEM if returns NULL. Moreover, because the memory allocated with devm_kzalloc() will be freed automatically when the last reference to the device is dropped, the 'gbe' in gbaudio_tplg_create_enum_kctl() and gbaudio_tplg_create_enum_ctl() do not need to free manually. But the 'control' in gbaudio_tplg_create_widget() and gbaudio_tplg_process_kcontrols() has a specially error handle to cleanup. So it should be better to cleanup 'control' when fails. Fixes: e65579e335da ("greybus: audio: topology: Enable enumerated control support") Reviewed-by: Alex Elder Signed-off-by: Jiasheng Jiang Link: https://lore.kernel.org/r/20220104150628.1987906-1-jiasheng@iscas.ac.cn Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/greybus/audio_topology.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c index 7f7d558b76d04..62d7674852bec 100644 --- a/drivers/staging/greybus/audio_topology.c +++ b/drivers/staging/greybus/audio_topology.c @@ -147,6 +147,9 @@ static const char **gb_generate_enum_strings(struct gbaudio_module_info *gb, items = le32_to_cpu(gbenum->items); strings = devm_kcalloc(gb->dev, items, sizeof(char *), GFP_KERNEL); + if (!strings) + return NULL; + data = gbenum->names; for (i = 0; i < items; i++) { @@ -655,6 +658,8 @@ static int gbaudio_tplg_create_enum_kctl(struct gbaudio_module_info *gb, /* since count=1, and reg is dummy */ gbe->items = le32_to_cpu(gb_enum->items); gbe->texts = gb_generate_enum_strings(gb, gb_enum); + if (!gbe->texts) + return -ENOMEM; /* debug enum info */ dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->items, @@ -862,6 +867,8 @@ static int gbaudio_tplg_create_enum_ctl(struct gbaudio_module_info *gb, /* since count=1, and reg is dummy */ gbe->items = le32_to_cpu(gb_enum->items); gbe->texts = gb_generate_enum_strings(gb, gb_enum); + if (!gbe->texts) + return -ENOMEM; /* debug enum info */ dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->items, @@ -1072,6 +1079,10 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module, csize += le16_to_cpu(gbenum->names_length); control->texts = (const char * const *) gb_generate_enum_strings(module, gbenum); + if (!control->texts) { + ret = -ENOMEM; + goto error; + } control->items = le32_to_cpu(gbenum->items); } else { csize = sizeof(struct gb_audio_control); @@ -1181,6 +1192,10 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module, csize += le16_to_cpu(gbenum->names_length); control->texts = (const char * const *) gb_generate_enum_strings(module, gbenum); + if (!control->texts) { + ret = -ENOMEM; + goto error; + } control->items = le32_to_cpu(gbenum->items); } else { csize = sizeof(struct gb_audio_control); -- 2.34.1