From patchwork Sun Jul 7 11:48:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13726003 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 33D01C30653 for ; Sun, 7 Jul 2024 11:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=GJ4/E9J4xI4cimYcWsERwrFehVb+qxmPhq/NewCkOwc=; b=IVx1V152xjkaXLC/2NCMJ01jAH o5QM1UU95MV+3cJWLWxRxFzHMy4B/yrsZ+mCVcfeucHvbtjPh6WQquTUWut3t3Chw1tPqtRjukiHa r58+L75k5KNIHCkPsTF+U4TDdDU4gIVsFN4WRbVTzck9uyG1FMZz+movgO8qqS/Mkyy70kINO6wZb QgvWeaVknaGB7q6VDK3UvMVkaR65c8ihW7REEnzykhiAXrwyfrDW0/wDPTfB40ENCiJgJWx3ot+ty cbk6hOdR2SjPeUt+nzk2aQ09RTO+UbA/XczlU40JfikxI9fTVWA26Heci1bfzQoVr6a6XMHGqa+52 M2DWiVKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQQNp-00000001i5T-16LO; Sun, 07 Jul 2024 11:48:45 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQQNa-00000001i1i-0Vpo for linux-arm-kernel@lists.infradead.org; Sun, 07 Jul 2024 11:48:32 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4265ddc879aso7927005e9.0 for ; Sun, 07 Jul 2024 04:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720352908; x=1720957708; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GJ4/E9J4xI4cimYcWsERwrFehVb+qxmPhq/NewCkOwc=; b=mM/Hjl8lnlixKog4gvg1bKf5xb3kSzwPGveHQqTk78/nDs99G3RsV7zoAb9ugEDH0i dufJqvKXVlCIwp97gXlg/xjbq6bxFbGG8/HJyeQlK8XjFcg+yPXacELs2xgJ6J12PO1B wYYrKbQUaDIHx6K6k9HisM2pfJ4jYTKad8NCVmNGPvt4RqLD0LvRMHiBESx6yOaVASFo AYqcv8BkT3wNv0i6dUQnDZmkQIgMCE3fXooSgb/k86xzgLJ6++7TUTIHfJ5lErOL0DL/ m3YclMm/BGcTYMLb7nnBDycQmK3AhP2X3tbVw7RsY9sPkrZZ2z4I2QvHOQRSoGeFiDwn ltKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720352908; x=1720957708; 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=GJ4/E9J4xI4cimYcWsERwrFehVb+qxmPhq/NewCkOwc=; b=Hp5Wzqzogxcw74PPZhafEXA8l6p4QQifwY4fLUCgoiBWpivf4swYZMQj9xQgIek4kc 14ha96s1OOeZ+dFHEybdV2BWQmU7npXHrAmidFlLBsuk/pAJUrajs6qngthYiA6zBWwS k6ILuY6vOt9YKfm3HJtZvXJdDvuOoSMmF84eZ0jomM4GG/EloWUuiAiKAfSrdk7AfpFf 5NspepL8jcPtF0gMuN3GwVSMojSBHun8EE/dgjvf+tG+XVnutXhSa+1XGdlTEhnL5OH8 s/d4gxEAQk7tiusn3IP+9nXira8TEwFJFAn5etUxbm+di0LjI6ihAc5vFIdJOD1ANOuD 3fBw== X-Forwarded-Encrypted: i=1; AJvYcCWpissvCbtGoS3RrKEGNn8SFyK73z9fliYIzfJhBGRwlgoF8TAIELP3UcaPlJiaJeG3vjlJwsVZcwnlxen+KogbeJXmkp+jOLYswfYD/XJaiDRAaPA= X-Gm-Message-State: AOJu0YwneKoyFFIzSKfVo8pxERB/IzLVLK7ArEuCoZhdZyfCBcJr40N7 EpA0lcii1uT6amC+OFvA+34AwXi8NXCcVdovEUIYoMtQx3cpJX6+jj9Yw3bw/9kZ/9SaWzN8N30 g X-Google-Smtp-Source: AGHT+IEI6lDV64Hl12cyK3t6agUGUkDoFIW2n3pq5pOaxd9XBSBXy4giAuXzNO3Rsklt90kI7V0pLw== X-Received: by 2002:a05:600c:1d90:b0:426:6960:34ac with SMTP id 5b1f17b1804b1-4266960362emr1276995e9.36.1720352907837; Sun, 07 Jul 2024 04:48:27 -0700 (PDT) Received: from krzk-bin.. ([178.197.219.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367b09401d3sm4926279f8f.28.2024.07.07.04.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jul 2024 04:48:27 -0700 (PDT) From: Krzysztof Kozlowski To: Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Krzysztof Kozlowski Subject: [PATCH 1/2] mfd: mt6360: Simplify with cleanup.h Date: Sun, 7 Jul 2024 13:48:22 +0200 Message-ID: <20240707114823.9175-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240707_044830_190086_DEE5B448 X-CRM114-Status: GOOD ( 14.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allocate the memory with scoped/cleanup.h to reduce error handling and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski --- drivers/mfd/mt6360-core.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 2685efa5c9e2..b9b1036c8ff4 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -5,6 +5,7 @@ * Author: Gene Chen */ +#include #include #include #include @@ -404,7 +405,6 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size, u8 reg_addr = *(u8 *)(reg + 1); struct i2c_client *i2c; bool crc_needed = false; - u8 *buf; int buf_len = MT6360_ALLOC_READ_SIZE(val_size); int read_size = val_size; u8 crc; @@ -423,7 +423,7 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size, read_size += MT6360_CRC_CRC8_SIZE; } - buf = kzalloc(buf_len, GFP_KERNEL); + u8 *buf __free(kfree) = kzalloc(buf_len, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -433,24 +433,19 @@ static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size, ret = i2c_smbus_read_i2c_block_data(i2c, reg_addr, read_size, buf + MT6360_CRC_PREDATA_OFFSET); if (ret < 0) - goto out; - else if (ret != read_size) { - ret = -EIO; - goto out; - } + return ret; + else if (ret != read_size) + return -EIO; if (crc_needed) { crc = crc8(ddata->crc8_tbl, buf, val_size + MT6360_CRC_PREDATA_OFFSET, 0); - if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET]) { - ret = -EIO; - goto out; - } + if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET]) + return -EIO; } memcpy(val, buf + MT6360_CRC_PREDATA_OFFSET, val_size); -out: - kfree(buf); - return (ret < 0) ? ret : 0; + + return 0; } static int mt6360_regmap_write(void *context, const void *val, size_t val_size) From patchwork Sun Jul 7 11:48:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Kozlowski X-Patchwork-Id: 13726004 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 56831C30653 for ; Sun, 7 Jul 2024 11:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Aj+H9xvUnyjT7MSWsF+iRqKuLRi/HfbWIla1Bmzx9bg=; b=brK/Yq4nMpUyKSOFdX2ykSN50X FIicH4/13UqPZ8PKokviwqz3JrM4f6LgJzF4c8cjdXrBBTw58uOk1Su8Y4ktun3j/PxGl5H3RqeGY EVg7uBntoMQ/u9wgWlxpljtOOC4cnX+DAz/SWTqs0CyJcNXKsdLlthF8WjJsxIiMsLB6EuDt+F8Dq ojFzVif2koxVGno1Fu6smSOfk0qqGFF6SGnMhaFz5G9HK5neJA9VHy0Hq5OqlyhRtlb8c0+61E1QZ o/DD8iujQesL0xzSOj1q5i2TuhKh2+pyJxcVZ1BdGAV3Yp8u0q7MVfLEDiX7BVMJQJjAjASqqePVk 2YMKyp1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQQO1-00000001i9y-3Eqe; Sun, 07 Jul 2024 11:48:57 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQQNa-00000001i1m-405V for linux-arm-kernel@lists.infradead.org; Sun, 07 Jul 2024 11:48:33 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3678f36f154so1586594f8f.2 for ; Sun, 07 Jul 2024 04:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720352909; x=1720957709; darn=lists.infradead.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=Aj+H9xvUnyjT7MSWsF+iRqKuLRi/HfbWIla1Bmzx9bg=; b=KQJCPYX/iB2jpAit4eZwAI8f8f/Oxf7+IvTYGzZverkFyosWV7QlwZnDROxxNo0zw8 23hGBKUThJ9zRcPRQkrF4CNVXd2+Ir4E9gieoHcE7uPPAE72gN64L9YXFPazbl01zMWX peCjr4YIWNIQFRex4uh23yVnTJV0NH27dLdHRLwf9QmkMLupoKVhogajphC1Hfr8VM4L 4/w+99iAssbVATC3xRqTDRtGvEAataQrgMOA6ewikuOE64bIBm6jojQg88Xw2lpkW913 WB3Un8GI5/a86o/kITP8I6fOs4skEgYSM0akbgwdFiAu3gLGA01G+5K5WL0o/kyyK6vO 9Uqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720352909; x=1720957709; 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=Aj+H9xvUnyjT7MSWsF+iRqKuLRi/HfbWIla1Bmzx9bg=; b=KAfsvPkrnlnNO0FxgEZR23t1bwiaYgpjh5vy06W1n03SALYEQ0wDW3G9+jOtgGTnho XJF/mLEjmSHrsx6wc3jqH7DWN/fthDeqEbryZJW4ozWJ03UDwI5rqd80py8WZFvL855C lHWziNUDubUFM/0sesFQnHjLmKWJnjyjrEVbvM4EtaiZumkTZ0E6gi287pByMJMaKxS4 Rt6Zlas/hfm6FKcDMIlqNMdnYez9SVgEOIIlHxJF7ICmVnPiqAJUUL/csaZpvYSTBYFW GXMLlqxf6BtmsQcFr7NrELFY+VrLh4/w37zQQd+9d8kh0VTleP9V/Cc9qsPB2ea6zZOq vZqg== X-Forwarded-Encrypted: i=1; AJvYcCUGvAcK/Yzpx0Cav8I0FJeTFjahn90I7EpWiM22ijS+s7hAyJ5pqYunn6peNIf+dpmbcJjYqWB9F/IPnpguqeEzLlLKhQfVtf2Z/iGqYKqnmHNWO5Y= X-Gm-Message-State: AOJu0YyTZVtYGHs0P9cFjjJk0ANn/H26GDTeZPD/ZTkSKn24xLuDQzYa P6GaYzKlw+1DWKruqLzXgCsPPqhbwEgnRki00fpDW2u3QCb37behC0gWxWutsag= X-Google-Smtp-Source: AGHT+IHeMOE4bOFQg+g/YY8EP60jFy+PSHmwQodEWUVahd9Sv7efipLc0NJkFBPW7S07o5gHz1LR0Q== X-Received: by 2002:adf:ab1c:0:b0:367:9791:f155 with SMTP id ffacd0b85a97d-3679dd55b9emr5247812f8f.40.1720352909065; Sun, 07 Jul 2024 04:48:29 -0700 (PDT) Received: from krzk-bin.. ([178.197.219.137]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-367b09401d3sm4926279f8f.28.2024.07.07.04.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jul 2024 04:48:28 -0700 (PDT) From: Krzysztof Kozlowski To: Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Krzysztof Kozlowski Subject: [PATCH 2/2] mfd: syscon: Simplify with cleanup.h Date: Sun, 7 Jul 2024 13:48:23 +0200 Message-ID: <20240707114823.9175-2-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240707114823.9175-1-krzysztof.kozlowski@linaro.org> References: <20240707114823.9175-1-krzysztof.kozlowski@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240707_044830_999152_9AC4F5D2 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allocate the memory with scoped/cleanup.h to reduce error handling and make the code a bit simpler. Signed-off-by: Krzysztof Kozlowski --- drivers/mfd/syscon.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c index 7d0e91164cba..c939a76e83b8 100644 --- a/drivers/mfd/syscon.c +++ b/drivers/mfd/syscon.c @@ -8,6 +8,7 @@ * Author: Dong Aisheng */ +#include #include #include #include @@ -45,7 +46,6 @@ static const struct regmap_config syscon_regmap_config = { static struct syscon *of_syscon_register(struct device_node *np, bool check_res) { struct clk *clk; - struct syscon *syscon; struct regmap *regmap; void __iomem *base; u32 reg_io_width; @@ -54,20 +54,16 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res) struct resource res; struct reset_control *reset; - syscon = kzalloc(sizeof(*syscon), GFP_KERNEL); + struct syscon *syscon __free(kfree) = kzalloc(sizeof(*syscon), GFP_KERNEL); if (!syscon) return ERR_PTR(-ENOMEM); - if (of_address_to_resource(np, 0, &res)) { - ret = -ENOMEM; - goto err_map; - } + if (of_address_to_resource(np, 0, &res)) + return ERR_PTR(-ENOMEM); base = of_iomap(np, 0); - if (!base) { - ret = -ENOMEM; - goto err_map; - } + if (!base) + return ERR_PTR(-ENOMEM); /* Parse the device's DT node for an endianness specification */ if (of_property_read_bool(np, "big-endian")) @@ -152,7 +148,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res) list_add_tail(&syscon->list, &syscon_list); spin_unlock(&syscon_list_slock); - return syscon; + return_ptr(syscon); err_reset: reset_control_put(reset); @@ -163,8 +159,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res) regmap_exit(regmap); err_regmap: iounmap(base); -err_map: - kfree(syscon); return ERR_PTR(ret); }