Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3586439pxb; Mon, 24 Jan 2022 12:53:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkBjCumKuR0gkMEkpYtU304tMCXksBqLyZNm3/OwLql+94yydviOaG5yFPtoCwOaiwlkNg X-Received: by 2002:a17:903:120a:b0:149:8b16:ee19 with SMTP id l10-20020a170903120a00b001498b16ee19mr16474830plh.11.1643057617588; Mon, 24 Jan 2022 12:53:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057617; cv=none; d=google.com; s=arc-20160816; b=hD2Xy+9dj09Jnss3ghCEmMjiI+z6xPyF0vm2YLD4QEHDMbBPCg/Cson/O0E+qhxrsF v1gDtAjciN0joA0i4qloN0FJBslzdjsIfF8OgsfgyLbqT5rMxoRh1gRedDpf8WOv4Eja jllAf4aPEWYtRbZeKm4jsbwtuZauG9ReB4fZVg57yKTEtlz+dc/UQdTaMq0U62LVZpha cSvc/teHQfSdsVcquKW5sIy1i5Tk7hhgz3GkbG9PrisiO524W9nref0pKZZVMKa3HQag 2jImoXC5h6Vml1cbi5uryaKSTBpzCZ/drbI92Yn/lnLU4foIrSRr90EfRFtDyHkKhK38 t0hg== 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=9rWZ24FwoaThPS1f8/fsxMUJGVX/tAReno093/qOPw8=; b=KmldsWD3CEOJY7Ia5Qay0dY19ZoB+Rp2Vu2cKAfFO58/E4djCOtNjUxirELYI6bntr gxZJ7VoiPYeSt8DMgJkO5qqrKXa026aooBODmsKCOxUA/B3tfIzARfh4XmYz98CP/Ngg UqyWO88DPthsLeEUor+WGrx8xyxzb4g9VmuyOJ/tFyVNqSEpOARIupK3zCpwZQMrfG5P L6C7/XAraLbvMX4RPAR+EMabfpVGQTsIvRfc08kKa1HWTuY2O31lxRhpKANf4XDmhTtt u9ricfdabPP3nTGQJ4nRuBcarLkFn2SxRtXabF626QTlmur76zzKZKv789BH9YjV5pKe YLuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=urk3XKZO; 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 r18si4161469plr.589.2022.01.24.12.53.25; Mon, 24 Jan 2022 12:53:37 -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=urk3XKZO; 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 S1353129AbiAXUON (ORCPT + 99 others); Mon, 24 Jan 2022 15:14:13 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:41328 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240135AbiAXTxp (ORCPT ); Mon, 24 Jan 2022 14:53:45 -0500 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 0087FB81218; Mon, 24 Jan 2022 19:53:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89D87C36AE3; Mon, 24 Jan 2022 19:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643054022; bh=eoSpb2Jjaa/VzEtSTqkkOb08WYHFLtrDP1lBsjhRaGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=urk3XKZOYcJ1EJZM6QHATZZkUyfzw2RiDdiF/lfQYqi2KylcyRRr64rKUek3VG3a1 GrWCOoxcyMpk9bCypJkPZQFdgw9JXfIn62c1P+lHdmeM5ufnO/UzIG5YHPvUkU9fbR SPmahl3yYTqR2YbId9yYyxJigC7FCgVrYDITGxgE= 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.10 210/563] staging: greybus: audio: Check null pointer Date: Mon, 24 Jan 2022 19:39:35 +0100 Message-Id: <20220124184031.699760005@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184024.407936072@linuxfoundation.org> References: <20220124184024.407936072@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 2bb8e7b60e8d5..e1579f356af5c 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