From patchwork Mon Jun 3 10:28:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= X-Patchwork-Id: 801276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE7C7C25B76 for ; Mon, 3 Jun 2024 10:29:04 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 147201DF; Mon, 3 Jun 2024 12:28:53 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 147201DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1717410543; bh=67gZRlZBaTdb8h6ch3REGCduvNYrqRietV9ZHi2R820=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=FSDYrpW0Qly4HCRfb3ewNI4a8tA50teD3FBeUEcm4pRD2pPm4PSTW7bqEV5SiMhGr 87NUCXdjxU/+v1sCgpA3qz7thcYsCKWrvYVlrGQeZoOpG5RlZ+amoMPYC0qUqn7jMe nnqPWTbTapbTSxL7LVzynjraCK9L69+yy1I8lZ44= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 49AAAF805EE; Mon, 3 Jun 2024 12:27:59 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B9607F805D2; Mon, 3 Jun 2024 12:27:58 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 00B39F80496; Mon, 3 Jun 2024 12:27:50 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id BD773F800FA for ; Mon, 3 Jun 2024 12:27:42 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BD773F800FA Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=RUTIRvov DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717410464; x=1748946464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=67gZRlZBaTdb8h6ch3REGCduvNYrqRietV9ZHi2R820=; b=RUTIRvovDgHz43t3rwO1WqR2Ht97jBqmXKH/2LroAeVkkWJGC9usYoTX AjCYSVA1ujECJFs9kv2cSJFEOsm4WVbC/dZxRfj2zGukbBQK1IsDJAVhH 5WZ0+3aON/wPQ3aejKqLfBMS5AOlZtvktVJz7ApAjF1Z2Em6qDuyQuvYn BKux1SOVYIcgZJNXhr995ucqaRJSHIvDQhjM6MgFu8FEa9VmsqVesVRA5 e5YlVUzlxceEzVGVIjcgJHGmvOj7BY4MyFu5X2vj94n2UdkSXPNFWeonB w0buvAdqBNGhwSOzqBuUwTgIulB20gjJ3fHb6Y8ovJTciJdM8uOt8CLfn Q==; X-CSE-ConnectionGUID: 9efDAc0sRtmK2odysyuPYw== X-CSE-MsgGUID: 4b/VttfSStqSe8stfdG1IA== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="14017221" X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="14017221" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2024 03:27:42 -0700 X-CSE-ConnectionGUID: IKnj8+OsS4m1S9+F3bv42g== X-CSE-MsgGUID: zuxYrlauT5e6p3GtU3jHtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="37430042" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orviesa008.jf.intel.com with ESMTP; 03 Jun 2024 03:27:40 -0700 From: =?utf-8?q?Amadeusz_S=C5=82awi=C5=84ski?= To: Mark Brown Cc: Cezary Rojewski , Pierre-Louis Bossart , Ranjani Sridharan , Takashi Iwai , Jaroslav Kysela , alsa-devel@alsa-project.org, linux-sound@vger.kernel.org, Jason Montleon , =?utf-8?q?Amadeusz_S=C5=82awi=C5=84sk?= =?utf-8?q?i?= Subject: [PATCH 2/4] ASoC: Intel: avs: Fix route override Date: Mon, 3 Jun 2024 12:28:16 +0200 Message-Id: <20240603102818.36165-3-amadeuszx.slawinski@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603102818.36165-1-amadeuszx.slawinski@linux.intel.com> References: <20240603102818.36165-1-amadeuszx.slawinski@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: NVRTQON52FZO3YBOZYXDODB6WNONVQBA X-Message-ID-Hash: NVRTQON52FZO3YBOZYXDODB6WNONVQBA X-MailFrom: amadeuszx.slawinski@linux.intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Instead of overriding existing memory strings that may be too short, just allocate needed memory and point the route at it. Reported-by: Jason Montleon Link: https://github.com/thesofproject/avs-topology-xml/issues/22#issuecomment-2127892605 Reviewed-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński --- sound/soc/intel/avs/topology.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sound/soc/intel/avs/topology.c b/sound/soc/intel/avs/topology.c index 02bae207f6ece..b6c5d94a15548 100644 --- a/sound/soc/intel/avs/topology.c +++ b/sound/soc/intel/avs/topology.c @@ -1545,8 +1545,8 @@ static int avs_route_load(struct snd_soc_component *comp, int index, { struct snd_soc_acpi_mach *mach = dev_get_platdata(comp->card->dev); size_t len = SNDRV_CTL_ELEM_ID_NAME_MAXLEN; - char buf[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; int ssp_port, tdm_slot; + char *buf; /* See parse_link_formatted_string() for dynamic naming when(s). */ if (!avs_mach_singular_ssp(mach)) @@ -1557,13 +1557,24 @@ static int avs_route_load(struct snd_soc_component *comp, int index, return 0; tdm_slot = avs_mach_ssp_tdm(mach, ssp_port); + buf = devm_kzalloc(comp->card->dev, len, GFP_KERNEL); + if (!buf) + return -ENOMEM; avs_ssp_sprint(buf, len, route->source, ssp_port, tdm_slot); - strscpy((char *)route->source, buf, len); + route->source = buf; + + buf = devm_kzalloc(comp->card->dev, len, GFP_KERNEL); + if (!buf) + return -ENOMEM; avs_ssp_sprint(buf, len, route->sink, ssp_port, tdm_slot); - strscpy((char *)route->sink, buf, len); + route->sink = buf; + if (route->control) { + buf = devm_kzalloc(comp->card->dev, len, GFP_KERNEL); + if (!buf) + return -ENOMEM; avs_ssp_sprint(buf, len, route->control, ssp_port, tdm_slot); - strscpy((char *)route->control, buf, len); + route->control = buf; } return 0;