From patchwork Mon Jul 1 17:19:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13718477 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFE1016EB46 for ; Mon, 1 Jul 2024 17:19:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719854364; cv=none; b=k5t2gkViLdKxs4Zlo6Yqr1bbHc6ujWVnFKg8fhtoLdVnjKSZ2Gn+bQwcjQ8o7tCK/AVaNBMnTgmciEh675MinIbw1KMjSTJ4+/I+/hkvy1K5F9huFPDfZNvwB6vBorUhf9YSn9yZZtQlzVG9Jk6FVCrVJau5Kd3VZ+G8NeCf7iI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719854364; c=relaxed/simple; bh=dqfvYGwmOKhaiFHa1zCpcfeOXkzk+rPswzjvChsg7so=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Gr7Ob7xl3Ko2sKfBD7OXvXavO7Ar6dRpAoRXdFNUY8MNiP4YOZEr7PbO9/QHwR8yiQ4262a3MW3WlvnC8jYSTtcwxOtevLfDKlx1X/nJECTz20DEytBnwEls62qlIDfQCWPlUQVvCU49fj2U4J9/uZgf5mXSdhdX/9hCmeO7kSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=ReQDNhpW; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ReQDNhpW" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-424ad991c1cso29531185e9.1 for ; Mon, 01 Jul 2024 10:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719854361; x=1720459161; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=mFg/9L3rp+k4GtkOLXisVJYUePHQn+Z+ti8m2E06xN0=; b=ReQDNhpWTbRFiLMF4Hr49Gnu7i+sy3KClp048viN/0u6cX3G+ZiwoyDnMqUXdt5s85 0hMNdALmZgWKct8JhZT4Ogmz/z4Ui3GBBDJyhk+BIBR2fZFFcw58O9OFOgREl1xeDiPj UbmiTIYLZ9jb9LEjXWMgYaNCTnV4TRTJ7X6FV3TDYo1LZfuFh6MOQnHXr2BUjhm59L8x NXZ4JKXo37GfxcwFWzBYG12nWFLBSw05KGWuPooaaorI6P5qbEwckdfobI2O5SQc0Q3i yBJc3kmBpwJUhVtJNPUPEum/V+/HtVSOkTtvyw3aTaAv1cHR9jcFAkjW5zCBvftwJRRz JAAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719854361; x=1720459161; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mFg/9L3rp+k4GtkOLXisVJYUePHQn+Z+ti8m2E06xN0=; b=jc4e7zMZlO+TvChiLgotwM7y3lZqbCrCPv11kHg8zvnbPGEVEdDluoehA/dgaI81nL pFl0jzSja0x8HXvBnMRbEXjQ8H8OH+2JpbeUviDnTvqR76vP3PYF9RI8gX/d1ZhXsH4k 8c+APwp3ToKXKK5AS7pYE11Vcb4X1cFWQrJVgTJ1eVj9y824h6muShW1E11pGd3WvIJj xCJN8Yr8xdHauCmntXQc4e58fF6CRM512ckh/2+0016cHojKsUU0QDb5dQZildrvNpxP UPyLr5V4wvj8acw48G9N3AryNU6ke1i09hvFlUdzPsr7vlpARyL6D5x37/cLUZwZjPwA Ox/A== X-Forwarded-Encrypted: i=1; AJvYcCXrpQ2H99V70IJo4j1TdTn5T3KD4r8ciwujWPLozw4TovuPCiPC433U1dcuPiiQ8RXSO6h0OiBpae7fJvC4oGd7aoWqSd/rMdmxyPc= X-Gm-Message-State: AOJu0Yyi1NWTLccQSPjCzJSsNnAugat+EXBmL7Nsgp5AO/S7WNS0pu0P gcLxusL6eV1M/6pehblLZYULYUZo7mtQxe4g9nwUMfdaN+grD1nCzLpEl43J1v4= X-Google-Smtp-Source: AGHT+IHNR1ABH6PKyzk7JMg6Jn5J0bcvxQEYovEtPBYvIHQfTDJs3e3xsSp6WhWeIyvAPFDDKwmFyw== X-Received: by 2002:a5d:5f56:0:b0:367:437f:1785 with SMTP id ffacd0b85a97d-3677569950bmr5309302f8f.13.1719854360985; Mon, 01 Jul 2024 10:19:20 -0700 (PDT) Received: from krzk-bin.. ([178.197.219.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a112e19sm10581137f8f.116.2024.07.01.10.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 10:19:20 -0700 (PDT) From: Krzysztof Kozlowski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Srinivas Kandagatla , Banajit Goswami , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH 1/2] ASoC: codecs: aw88395: Simplify with cleanup.h Date: Mon, 1 Jul 2024 19:19:16 +0200 Message-ID: <20240701171917.596173-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allocate memory, which is being freed at end of the scope, with scoped/cleanup.h to reduce number of error paths and make code a bit simpler. Signed-off-by: Krzysztof Kozlowski --- sound/soc/codecs/aw88395/aw88395_lib.c | 51 +++++++++----------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/sound/soc/codecs/aw88395/aw88395_lib.c b/sound/soc/codecs/aw88395/aw88395_lib.c index f25f6e0d4428..769ca32a5c8e 100644 --- a/sound/soc/codecs/aw88395/aw88395_lib.c +++ b/sound/soc/codecs/aw88395/aw88395_lib.c @@ -7,6 +7,7 @@ // Author: Bruce zhao // +#include #include #include #include "aw88395_lib.h" @@ -361,11 +362,11 @@ static int aw_dev_parse_raw_dsp_fw(unsigned char *data, unsigned int data_len, static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char *data, unsigned int data_len, struct aw_prof_desc *prof_desc) { - struct aw_bin *aw_bin; int ret; int i; - aw_bin = devm_kzalloc(aw_dev->dev, data_len + sizeof(struct aw_bin), GFP_KERNEL); + struct aw_bin *aw_bin __free(kfree) = kzalloc(data_len + sizeof(struct aw_bin), + GFP_KERNEL); if (!aw_bin) return -ENOMEM; @@ -375,7 +376,7 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char * ret = aw_parsing_bin_file(aw_dev, aw_bin); if (ret < 0) { dev_err(aw_dev->dev, "parse bin failed"); - goto parse_bin_failed; + return ret; } for (i = 0; i < aw_bin->all_bin_parse_num; i++) { @@ -387,10 +388,8 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char * data + aw_bin->header_info[i].valid_data_addr; break; case DATA_TYPE_DSP_REG: - if (aw_bin->header_info[i].valid_data_len & 0x01) { - ret = -EINVAL; - goto parse_bin_failed; - } + if (aw_bin->header_info[i].valid_data_len & 0x01) + return -EINVAL; swab16_array((u16 *)(data + aw_bin->header_info[i].valid_data_addr), aw_bin->header_info[i].valid_data_len >> 1); @@ -402,10 +401,8 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char * break; case DATA_TYPE_DSP_FW: case DATA_TYPE_SOC_APP: - if (aw_bin->header_info[i].valid_data_len & 0x01) { - ret = -EINVAL; - goto parse_bin_failed; - } + if (aw_bin->header_info[i].valid_data_len & 0x01) + return -EINVAL; swab16_array((u16 *)(data + aw_bin->header_info[i].valid_data_addr), aw_bin->header_info[i].valid_data_len >> 1); @@ -422,20 +419,17 @@ static int aw_dev_prof_parse_multi_bin(struct aw_device *aw_dev, unsigned char * } } prof_desc->prof_st = AW88395_PROFILE_OK; - ret = 0; -parse_bin_failed: - devm_kfree(aw_dev->dev, aw_bin); - return ret; + return 0; } static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev, uint8_t *data, uint32_t data_len, struct aw_prof_desc *prof_desc) { - struct aw_bin *aw_bin; int ret; - aw_bin = devm_kzalloc(aw_dev->dev, data_len + sizeof(*aw_bin), GFP_KERNEL); + struct aw_bin *aw_bin __free(kfree) = kzalloc(data_len + sizeof(*aw_bin), + GFP_KERNEL); if (!aw_bin) return -ENOMEM; @@ -445,14 +439,13 @@ static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev, ret = aw_parsing_bin_file(aw_dev, aw_bin); if (ret < 0) { dev_err(aw_dev->dev, "parse bin failed"); - goto parse_bin_failed; + return ret; } if ((aw_bin->all_bin_parse_num != 1) || (aw_bin->header_info[0].bin_data_type != DATA_TYPE_REGISTER)) { dev_err(aw_dev->dev, "bin num or type error"); - ret = -EINVAL; - goto parse_bin_failed; + return -EINVAL; } prof_desc->sec_desc[AW88395_DATA_TYPE_REG].data = @@ -461,15 +454,7 @@ static int aw_dev_parse_reg_bin_with_hdr(struct aw_device *aw_dev, aw_bin->header_info[0].valid_data_len; prof_desc->prof_st = AW88395_PROFILE_OK; - devm_kfree(aw_dev->dev, aw_bin); - aw_bin = NULL; - return 0; - -parse_bin_failed: - devm_kfree(aw_dev->dev, aw_bin); - aw_bin = NULL; - return ret; } static int aw_dev_parse_data_by_sec_type(struct aw_device *aw_dev, struct aw_cfg_hdr *cfg_hdr, @@ -678,21 +663,21 @@ static int aw_dev_cfg_get_multiple_valid_prof(struct aw_device *aw_dev, static int aw_dev_load_cfg_by_hdr(struct aw_device *aw_dev, struct aw_cfg_hdr *prof_hdr) { - struct aw_all_prof_info *all_prof_info; int ret; - all_prof_info = devm_kzalloc(aw_dev->dev, sizeof(struct aw_all_prof_info), GFP_KERNEL); + struct aw_all_prof_info *all_prof_info __free(kfree) = kzalloc(sizeof(*all_prof_info), + GFP_KERNEL); if (!all_prof_info) return -ENOMEM; ret = aw_dev_parse_dev_type(aw_dev, prof_hdr, all_prof_info); if (ret < 0) { - goto exit; + return ret; } else if (ret == AW88395_DEV_TYPE_NONE) { dev_dbg(aw_dev->dev, "get dev type num is 0, parse default dev"); ret = aw_dev_parse_dev_default_type(aw_dev, prof_hdr, all_prof_info); if (ret < 0) - goto exit; + return ret; } switch (aw_dev->prof_data_type) { @@ -710,8 +695,6 @@ static int aw_dev_load_cfg_by_hdr(struct aw_device *aw_dev, if (!ret) aw_dev->prof_info.prof_name_list = profile_name; -exit: - devm_kfree(aw_dev->dev, all_prof_info); return ret; } From patchwork Mon Jul 1 17:19:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13718478 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 497152B9DD for ; Mon, 1 Jul 2024 17:19:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719854365; cv=none; b=iQKzZg+fE4HqCujrjkahIXB8uu+OS++e5f1HePQUnp1XjQNznH0pkXhoxWXFNrtqwt6IL3fbrfherZ5H16E3K8ukVn9XE3EdCsnkioDrhfEoyCErHdr2YGXow7m/9IpbHIVmALNB9Nl4mQkR7qQ0gO0eXnL232YMUTwvncuBUXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719854365; c=relaxed/simple; bh=P21qd1OkbuiMrCjx3m8pH2sGiiMR71WkUYVgzpHXae8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VkuQzFNSPWO3AcJjdIuYbJ1EvBk/EMqUkiPet62Noyg2doWnYx5raCdilLheSN/n+fSfgpYzmlx56Lu77gvJUsblvVJSYsq6IqvjHJskuuKYSLHSi4Wf1w8lZE0oKy4dKNQOvGx5yMdZQquNghiIgxGqwNN3wbDZzKKg8Krbx/I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=iUpFkhh/; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iUpFkhh/" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-52ce6c8db7bso4885478e87.1 for ; Mon, 01 Jul 2024 10:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719854362; x=1720459162; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yqja86UDKTFIc+qc3NF0+FAZFhHDXQ4XzxpjOTJHZXE=; b=iUpFkhh/nSsOntn7LxJqxDqyniQjpbI6xZnHvMEP4jNzHazxAOJulCN9XGGoc2Kzgi 7WWFDXupEr1tHXxLC7DhaNvVD79LkoJz/S0fKks/CZ7n13W5DieE4vVjkvcvTdyfp/K8 DlqymiXUa4dJLZcAueyjs/iUdXUq+qypotFz8r2JR/GMO6yVoPRNiEZz3use97cLiWz8 IDs9olCcy9m8uukiqQ1BTs456ONhXIwBkSTbft09sBCiEY/WZbOrr96O5U1Et0AKNHAz EK68FUvsgsC3RILJkAnb5Vsj+OVGM26wAgCwo+matXqBLxhkQENtscLRbRkbgsSAcY5q w6sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719854362; x=1720459162; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yqja86UDKTFIc+qc3NF0+FAZFhHDXQ4XzxpjOTJHZXE=; b=soo/nxesG/H/LKOwOlxpUy0M090Euw48GCpADXpqhon1vTWq1V7/YZ1Yt7VpwfGoQl V7lk8TX2x1xS1HMvR+k1tkAvJj2EXL+9Bk8eoSAsqDNDcwmis8t87VpSz4puhHO5sb72 sH1DYfgwffNLR5x+n45zbMKykMSEHR5TZD0JJ4ZEKZovD3/2UczMk52N01n1Y1NT6EeL 714B2Di+EdnD0Ddugc+Sqei8lNd1QONDk2nfX1fJvamL0riuHhQbZJen9shfzy7F4Z2T 2rP1zMgfbWsliz+Fx3r9LS8yEmX6/Fnc0IZIM+z58EYasJE0rtERXal6O0pBx7kXxJeQ ZuMg== X-Forwarded-Encrypted: i=1; AJvYcCWZhjBFFsdCouZVxEyWgHM+Ws1sxThmla2STmNz7nBqAsOjOEFRRf2ZY8Hm+8WJz/SZudCyrW1qeP2fIIElmDdVSr8RDZqCT74bOz8= X-Gm-Message-State: AOJu0YwR0TcOtisGUyxPuVDj+4WtPKVwwSYGXACvBRf19L2rETETK0+H khxX3ONtFo89Uxoa6+xcEObrB6NDVhRd+dNuj/bz83dUzXMEpEYgID5cTZfkKmc= X-Google-Smtp-Source: AGHT+IEpcOPlfAXhpzDXXuXPLW36uadem/IXz8BjMrFDaiR4x1PqQz5+4iXhrAFqE4LAPZjFn+z0sg== X-Received: by 2002:a05:6512:1599:b0:52c:dc69:28f3 with SMTP id 2adb3069b0e04-52e8270fa7dmr4370670e87.52.1719854362487; Mon, 01 Jul 2024 10:19:22 -0700 (PDT) Received: from krzk-bin.. ([178.197.219.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a112e19sm10581137f8f.116.2024.07.01.10.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 10:19:22 -0700 (PDT) From: Krzysztof Kozlowski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Srinivas Kandagatla , Banajit Goswami , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH 2/2] ASoC: qcom: topology: Simplify with cleanup.h Date: Mon, 1 Jul 2024 19:19:17 +0200 Message-ID: <20240701171917.596173-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240701171917.596173-1-krzysztof.kozlowski@linaro.org> References: <20240701171917.596173-1-krzysztof.kozlowski@linaro.org> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Allocate memory, which is being freed at end of the scope, with scoped/cleanup.h to reduce number of error paths and make code a bit simpler. Signed-off-by: Krzysztof Kozlowski --- sound/soc/qcom/qdsp6/topology.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sound/soc/qcom/qdsp6/topology.c b/sound/soc/qcom/qdsp6/topology.c index f4d62ea60baa..83319a928f29 100644 --- a/sound/soc/qcom/qdsp6/topology.c +++ b/sound/soc/qcom/qdsp6/topology.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (c) 2020, Linaro Limited +#include #include #include #include @@ -1288,18 +1289,19 @@ int audioreach_tplg_init(struct snd_soc_component *component) struct snd_soc_card *card = component->card; struct device *dev = component->dev; const struct firmware *fw; - char *tplg_fw_name; int ret; /* Inline with Qualcomm UCM configs and linux-firmware path */ - tplg_fw_name = kasprintf(GFP_KERNEL, "qcom/%s/%s-tplg.bin", card->driver_name, card->name); + char *tplg_fw_name __free(kfree) = kasprintf(GFP_KERNEL, "qcom/%s/%s-tplg.bin", + card->driver_name, + card->name); if (!tplg_fw_name) return -ENOMEM; ret = request_firmware(&fw, tplg_fw_name, dev); if (ret < 0) { dev_err(dev, "tplg firmware loading %s failed %d\n", tplg_fw_name, ret); - goto err; + return ret; } ret = snd_soc_tplg_component_load(component, &audioreach_tplg_ops, fw); @@ -1309,8 +1311,6 @@ int audioreach_tplg_init(struct snd_soc_component *component) } release_firmware(fw); -err: - kfree(tplg_fw_name); return ret; }