From patchwork Mon Jun 3 10:28:15 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: 13683576 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 smtp.subspace.kernel.org (Postfix) with ESMTPS id 2004081AC7 for ; Mon, 3 Jun 2024 10:27:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410461; cv=none; b=LldKl08kbpZcPFBkeg4e/yftmksDiuETHyANIGJJ6U6SUJcaZ97yd86RViNANmDiukmaNcuuKuA1qz4Yq7csrVVUVnUvWwn5tIzygtmcA3r9t2JA7mB4iWScLWJVXG4LLyEF0tzCi2iHiOqGT7PsVgLf4TFcs7mXckjFjw5FagY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410461; c=relaxed/simple; bh=7NV3o9KauOpeQYT9WlCJbRb3c/G3kEQbMf65uPt62WU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MH42eXZQYrtygchRMNj5t76+wi8AM1QRwjvWRShSHFLfQFGgmwubkbF3IDgfhTNCCugStE3k3HBONpKQJvTfZAcVUCq7SKn/xBQk5gCKd6N6fAH/MKynv5Fu2KbbnrB8bUgg0HD2rIQXKufstkz29vIIiAwF5x1Gc0c6DmbjRMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Chxoys6h; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Chxoys6h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717410460; x=1748946460; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7NV3o9KauOpeQYT9WlCJbRb3c/G3kEQbMf65uPt62WU=; b=Chxoys6hpSVKJ0IYxLEJ40gw9NIc6VGqsv4/pHvH+Y7XBYNUcKzeaBKy Zi/MFo+cKGjTlIza88CzsjSDdb9/uYd1pucRZvAzpr+hk7quWSWObHOEb 8rNLRXwXxM225IarD75n7adCRaltMBmSbvV1qEV0RZbLJX+u4f+axqtBs I1bw+S5GOjpRem7uvnALNvFrWnhZl6D5FrTWIE8MpklI1M46zuFXHOPuC 2tIv2fT3+WVgVRh2mNsY0j/g7C4Gno3GDpy9X7Vae1c3k8S0yuCwpYRjN OBnBiUuoWfU82vHzipaJuQv99fBIxE+6/IJWuIAL14RJJU2Q/hHTsPgC7 g==; X-CSE-ConnectionGUID: 9d71HD5MQgmTwsYN17h38w== X-CSE-MsgGUID: yN4yLc/PQMKdwsUEcriz3A== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="14017212" X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="14017212" 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:40 -0700 X-CSE-ConnectionGUID: LS3e7dOITR6X6UVDljEwfg== X-CSE-MsgGUID: cNZioXGnQBG8Y3II7cVKHQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="37430034" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orviesa008.jf.intel.com with ESMTP; 03 Jun 2024 03:27:38 -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 1/4] ASoC: topology: Fix references to freed memory Date: Mon, 3 Jun 2024 12:28:15 +0200 Message-Id: <20240603102818.36165-2-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> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most users after parsing a topology file, release memory used by it, so having pointer references directly into topology file contents is wrong. Use devm_kmemdup(), to allocate memory as needed. 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/soc-topology.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 90ca37e008b32..75d9395a18ed4 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1060,15 +1060,32 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, break; } - route->source = elem->source; - route->sink = elem->sink; + route->source = devm_kmemdup(tplg->dev, elem->source, + min(strlen(elem->source), + SNDRV_CTL_ELEM_ID_NAME_MAXLEN), + GFP_KERNEL); + route->sink = devm_kmemdup(tplg->dev, elem->sink, + min(strlen(elem->sink), SNDRV_CTL_ELEM_ID_NAME_MAXLEN), + GFP_KERNEL); + if (!route->source || !route->sink) { + ret = -ENOMEM; + break; + } /* set to NULL atm for tplg users */ route->connected = NULL; - if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) + if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) { route->control = NULL; - else - route->control = elem->control; + } else { + route->control = devm_kmemdup(tplg->dev, elem->control, + min(strlen(elem->control), + SNDRV_CTL_ELEM_ID_NAME_MAXLEN), + GFP_KERNEL); + if (!route->control) { + ret = -ENOMEM; + break; + } + } /* add route dobj to dobj_list */ route->dobj.type = SND_SOC_DOBJ_GRAPH; 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: 13683577 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 smtp.subspace.kernel.org (Postfix) with ESMTPS id 8535B81AC7 for ; Mon, 3 Jun 2024 10:27:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410464; cv=none; b=mU/0GcR1i5O0l2jcHxxi3F8akLG7d/viLFYd/GXWYaP4tAvRhoRGRXwxNnRIRWnB0u4+nb1pxYUBRtzHqNCGsKqo3Rq9d7BlKge9cZw4ohz9XHhUAw2XLvz4MjnEGc+RuA3ZQLrPkiD14mS5uJskb7e5h9IEtsyDsWeHP0N3JUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410464; c=relaxed/simple; bh=67gZRlZBaTdb8h6ch3REGCduvNYrqRietV9ZHi2R820=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=S3m0M0i0bNgvw7eYN3FM7d/WkqtyeaaCupE+cVAnmuySi15PGIDSHHy8PATfaSux6Tq3A6xtuhhzRr7VSfyJGKCLkfd2vSrNkUxEIypU/yGljee+AJH4YvMYjKpcYNscdxNhNB83OUjg/fb1GQsccBexnwwwVm3/pJcKQrPKnjU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MLqEymbT; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MLqEymbT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717410463; x=1748946463; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=67gZRlZBaTdb8h6ch3REGCduvNYrqRietV9ZHi2R820=; b=MLqEymbT4+5qQmIeE5OYAmBa6B30ik38ODHr/3Kfg+Fui7swTmHKZRnF AdkED2ANmB3rmuqgUWLDK4/FhdR4+/gxO5ob+bkZid9ETFevtIcESMf5g ENouYFD6TqunOOFHnPxKL653PiZJF6AApH1hscW985QHSrHur5q/8PZbD ixVsRmzGRqqgeW4ai/zAMYkynt8PWQTYz3SNNvmQMLUuC7HUTjaE0NDQk BA+CyGd13Phf7W2b84i5JpwMBP2+VHMrMRPj2fIUpOojmplRI+a0R9VWB /H07eOj9rsXM50q4EvBqb8+28wsPyS8n42q6APRC5WjJMgf3wWW6he+uv A==; X-CSE-ConnectionGUID: uvwf2POiRnKojQVxBIh8ag== X-CSE-MsgGUID: s7wfsD5sRdG2M2Wt2g0DIQ== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="14017219" X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="14017219" 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> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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; From patchwork Mon Jun 3 10:28:17 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: 13683578 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 smtp.subspace.kernel.org (Postfix) with ESMTPS id EB1CE81AC7 for ; Mon, 3 Jun 2024 10:27:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410466; cv=none; b=SgmkB4A+UvO+JyboKOWXw4Vmig9dmaCigEd+RUsT50L4IBSkPRGCz3LfdU4UNxSRqP9VoioYWxUoqJHtpKebEEe9BsBjHDb2d1DxQjo8uaao9Bv/5Aiio+vpPSfdRGMb4OXwS7srmtifwp4jq0Rd0K/vsL7mn5vbyIsQF8Xdf10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410466; c=relaxed/simple; bh=GFqX5r9hkOet5jHFaGDfztMJVt5pXGz34ax6hpUonoQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=eFSa7zYb+I0+061Ac8Km+Jlb4UMUdZJIZ9X68zskGQH8AqsDs3XZ8RESY+R8/aUhETLq3uGEAxFdGPdnQCHLbZMKcpLDwhrV1kUlYJPWQumgR/Gh0EEshthO+GhS+tJiADOZcvv1JA+ICBzsqj9jCAQBdVdPPGyA7jm0pH5z5WA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=O5nPzSUm; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="O5nPzSUm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717410465; x=1748946465; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GFqX5r9hkOet5jHFaGDfztMJVt5pXGz34ax6hpUonoQ=; b=O5nPzSUm3Z0WvqfJzW2VTAVP2yCn6CaK4arKBmwJWrC7YulWdwBr4eZ0 8Zl3Skh1lS4rguwRZt5zVT8Xa/CkkCGolDP5jzy2mqYk4CZeOcdfR17Uq 1yiqVUlr2Q2EbG/XpZubVfvQSXxj0CPz7ioWlAHo3da8K2QOyXdV5ThVo sJ37cFgAtK+JVg9qJaqVZ5FTa9LD0D2Xi5nlQWb7s/ZasDevbW/j6DaDG PA7UH+pdRt6GRHbo/5I6Uvgy6ktK7hegl/fUbGM1qOCBdYWxElVcBIGL0 LKurDDYmFC0elIK/HDmdQKHZPWLkZVVxURNropfwIkSGQs4JMKNAGUCuM g==; X-CSE-ConnectionGUID: Eg8dRGCVRxu5UobglTGq1A== X-CSE-MsgGUID: KTiu0PPFSl+mw9zVleQ+CQ== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="14017229" X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="14017229" 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:45 -0700 X-CSE-ConnectionGUID: FptEqLsIStuFGfizIt204Q== X-CSE-MsgGUID: 1hlQtdrKTgqqzIUQECmNXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="37430047" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orviesa008.jf.intel.com with ESMTP; 03 Jun 2024 03:27:42 -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 3/4] ASoC: topology: Do not assign fields that are already set Date: Mon, 3 Jun 2024 12:28:17 +0200 Message-Id: <20240603102818.36165-4-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> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The routes are allocated with kzalloc(), so all fields are zeroed by default, skip unnecessary assignments. Reviewed-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński --- sound/soc/soc-topology.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 75d9395a18ed4..1db540aaad451 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1072,11 +1072,7 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, break; } - /* set to NULL atm for tplg users */ - route->connected = NULL; - if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) { - route->control = NULL; - } else { + if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) != 0) { route->control = devm_kmemdup(tplg->dev, elem->control, min(strlen(elem->control), SNDRV_CTL_ELEM_ID_NAME_MAXLEN), From patchwork Mon Jun 3 10:28:18 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: 13683579 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 smtp.subspace.kernel.org (Postfix) with ESMTPS id 56A9A81AC7 for ; Mon, 3 Jun 2024 10:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410468; cv=none; b=ec+BLXQRnSKPzIVMU2afM6KuxNPH+o+zd4UPJhsBvU/PQB1WTLk1FJL++/wim1K3vi3W0N6Ap8oflo7puFG+9rKFaXZBheThTyr/3edDobe8L5cwWoY+o+BxJL9ipiA8fD0RlC9PxwkCw41EBSqxYd30Atjn1Zd38OUzBEFjads= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717410468; c=relaxed/simple; bh=mrRMoWmxvzrAwR8G9TNIstf0By3PMvXmJHxrOKbXUJo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=FrGGlMhSbYo0sGU1LaNn9H93UC7iWPGAGGvidmaVxzdWG9dEOEB6LNQVPYqEjvlqMSdSGPrzvspxehd28KhSkVJwKUqhE3n2uLj5h1QriXSIBGtViGzOpwQjQF+kmI3bwMIbcQOY0wglD1Rql+w30kXrIyPqkfayIGcR2jITLuU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jET2CJyE; arc=none smtp.client-ip=198.175.65.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jET2CJyE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717410467; x=1748946467; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mrRMoWmxvzrAwR8G9TNIstf0By3PMvXmJHxrOKbXUJo=; b=jET2CJyEGiXsSnnJruCzUne58nlGIIcAL/kdQzjscUNwxdvbeF9DZ948 yJLDYJiFGjE7O01f3tCuTxusH7e8SXjKmuvQaFeSeCKolBu0ec1DEj0de IX5Spy/rtgUMpwm1/ZD+i+EORcCKJoY8gxH3gcKtjQ0ECQoUvjpnuB2YD lECMK4BgsPxMoaaFwUx5oVo7+M8OBox8ADPAhcxjlIe9iwvgqLPojO2fa DtiDUAQ/AnyMekiOlFC0UHTzatcNpvavKljlDI0iD4whyn+Xtkh2DJtCj xyXUrzKp5oLpZiK/52VqG/WySIIgFPD6xv2pQojDxhg3oLOf5xSUwoyDR g==; X-CSE-ConnectionGUID: eSH/VXSESTGCcTarzaqNJg== X-CSE-MsgGUID: 5ttlCMtDSXqdOt//8i5aHw== X-IronPort-AV: E=McAfee;i="6600,9927,11091"; a="14017236" X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="14017236" 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:47 -0700 X-CSE-ConnectionGUID: TwKTajOsQoiHfU0xQ+QXkA== X-CSE-MsgGUID: 6/5mpYAsR/GfXFqanzGk5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,211,1712646000"; d="scan'208";a="37430053" Received: from dev2 (HELO DEV2.igk.intel.com) ([10.237.148.94]) by orviesa008.jf.intel.com with ESMTP; 03 Jun 2024 03:27:45 -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 4/4] ASoC: topology: Clean up route loading Date: Mon, 3 Jun 2024 12:28:18 +0200 Message-Id: <20240603102818.36165-5-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> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of using very long macro name, assign it to shorter variable and use it instead. While doing that, we can reduce multiple if checks using this define to one. Reviewed-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński --- sound/soc/soc-topology.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c index 1db540aaad451..2ac442644ed4f 100644 --- a/sound/soc/soc-topology.c +++ b/sound/soc/soc-topology.c @@ -1021,6 +1021,7 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, struct snd_soc_tplg_hdr *hdr) { struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; + const size_t maxlen = SNDRV_CTL_ELEM_ID_NAME_MAXLEN; struct snd_soc_tplg_dapm_graph_elem *elem; struct snd_soc_dapm_route *route; int count, i; @@ -1044,38 +1045,27 @@ static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem); /* validate routes */ - if (strnlen(elem->source, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == - SNDRV_CTL_ELEM_ID_NAME_MAXLEN) { - ret = -EINVAL; - break; - } - if (strnlen(elem->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == - SNDRV_CTL_ELEM_ID_NAME_MAXLEN) { - ret = -EINVAL; - break; - } - if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == - SNDRV_CTL_ELEM_ID_NAME_MAXLEN) { + if ((strnlen(elem->source, maxlen) == maxlen) || + (strnlen(elem->sink, maxlen) == maxlen) || + (strnlen(elem->control, maxlen) == maxlen)) { ret = -EINVAL; break; } route->source = devm_kmemdup(tplg->dev, elem->source, - min(strlen(elem->source), - SNDRV_CTL_ELEM_ID_NAME_MAXLEN), + min(strlen(elem->source), maxlen), GFP_KERNEL); route->sink = devm_kmemdup(tplg->dev, elem->sink, - min(strlen(elem->sink), SNDRV_CTL_ELEM_ID_NAME_MAXLEN), + min(strlen(elem->sink), maxlen), GFP_KERNEL); if (!route->source || !route->sink) { ret = -ENOMEM; break; } - if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) != 0) { + if (strnlen(elem->control, maxlen) != 0) { route->control = devm_kmemdup(tplg->dev, elem->control, - min(strlen(elem->control), - SNDRV_CTL_ELEM_ID_NAME_MAXLEN), + min(strlen(elem->control), maxlen), GFP_KERNEL); if (!route->control) { ret = -ENOMEM;