From patchwork Wed Mar 6 09:09:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pi-Hsun Shih X-Patchwork-Id: 10840639 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E121C1575 for ; Wed, 6 Mar 2019 09:10:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C98F42D462 for ; Wed, 6 Mar 2019 09:10:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C760D2D47D; Wed, 6 Mar 2019 09:10:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 550E82D453 for ; Wed, 6 Mar 2019 09:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nQak06gIFTNIg64WKPntEbyEDRv2dP7j7k9gQ1A19Ao=; b=ec+9F5AAUiNPKO ZS5ZJkQ0FyVi3tH9Z5v5y82JS3f+3XyX/cN6l26myHMes0Qbupd/USPaOBF2uUdfFVO10HnDMzKND lz9Ttn0J+2eIrtPcjvaHqnaMqNbA726ZG8sJad9m34mswjuwYnsT9d4b3JukCY3gc3LyZ1x2RJYps H7EHAyR4heY1oOLolflOUtjlviSZmvkwOerCFNarsLKtzlRQGctfL3yot9PHZwCvJfazcDx2D2iF7 xtpcdIY+N2cNPPg5Dy3fWkDlLOPUOF7cjMJ3HBu5vfC/I/sRxvZV5ozrl3P6+9q0fUHd0UUQ1/t/y E3utNxxVPDwrb4PDH7kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h1SZC-0002cL-2m; Wed, 06 Mar 2019 09:10:22 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h1SYv-0001PN-TT for linux-mediatek@lists.infradead.org; Wed, 06 Mar 2019 09:10:08 +0000 Received: by mail-pg1-x543.google.com with SMTP id r124so7885860pgr.3 for ; Wed, 06 Mar 2019 01:10:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wJOxMdrzk+4rw4ckkL08w9H5f7Ws6Ifi6+PYlrU/tu8=; b=ayg2KJ50bSe3ONjBVv6a41O2KKNtLE4IYgKzHSlVOOZ7x0HtLSTKQeKdFgmVAyjMl4 LhlT4BDZr/5b+WDGLfyjXH1QV0utAd0EPaVtRu+MxNarvox+4uJehsFCdhJOpWi/Sm/D r23aBSeLnUE+k/vvyXNk+IE+hLatrR1iIiYmw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wJOxMdrzk+4rw4ckkL08w9H5f7Ws6Ifi6+PYlrU/tu8=; b=JyAlzHXCCJ7OtRgK/HF0sDaWbYDjr7hZXvo9bbkH19GxfthbEA1IXC9USdB5a3k5Zn HIxw4j2dzv+AlgNnvlLP55GUrifzEqKJORUZKOupT1STSwWccSTWYwPVfExWuWxCOeve xH97sMqIWRSy3P6xJHBmN6SJh/Z36wHbZg1zdss+p7Qv3Dp45/xsuKe8ZoOBGQBHeFxI ysCES8mYq/nndBvhiAK43voFFM3cx/XGx3DHS2pC6xgVsgiCcyQ2e+hX5Sy5HRvq0f9A H96y/KR93ObZetmpHjFX7cNXZ9uXM8TQyKHLFkrLIRiZ7+6HHQveL2yUlChmX+RUP1or 2fQg== X-Gm-Message-State: APjAAAX28eMQW5Trzl9TbyG0DoI4cj64aNQi95pSi1c3kMiBf1OJUPZC hISP7imVjAIrXsernQp9GSPgsA== X-Google-Smtp-Source: APXvYqy3GUfcFcA+X45DUSEQSPjHmusKp3XjYJ6EugpfkOZ7uAOeg53Y0jL2JIjD1VrIiEGT/0f7NQ== X-Received: by 2002:a63:f806:: with SMTP id n6mr5332503pgh.19.1551863405373; Wed, 06 Mar 2019 01:10:05 -0800 (PST) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id h65sm1603710pgc.93.2019.03.06.01.10.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 01:10:04 -0800 (PST) From: Pi-Hsun Shih To: Subject: [PATCH 2/2] ASoC: mediatek: Reduce repititive code on mtk_regmap_update_bits. Date: Wed, 6 Mar 2019 17:09:03 +0800 Message-Id: <20190306090922.117634-3-pihsun@chromium.org> X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog In-Reply-To: <20190306090922.117634-1-pihsun@chromium.org> References: <20190306090922.117634-1-pihsun@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190306_011006_278992_1D522D8E X-CRM114-Status: GOOD ( 11.11 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Ryder Lee , open list , Garlic Tseng , Takashi Iwai , Liam Girdwood , Mark Brown , "moderated list:ARM/Mediatek SoC support" , Pi-Hsun Shih , Matthias Brugger , Jaroslav Kysela , "moderated list:ARM/Mediatek SoC support" Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Change the signature of mtk_regmap_update_bits to also take a shift, and warn when reg >= 0 but shift < 0. This reduce the code repetition on the calling side, and prevent future UBSAN warning when some of the xxx_shift and xxx_reg are both set to -1. Signed-off-by: Pi-Hsun Shih --- sound/soc/mediatek/common/mtk-afe-fe-dai.c | 46 +++++++++------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c index 3830e582e188..fded11d14cde 100644 --- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c +++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c @@ -18,11 +18,11 @@ static int mtk_regmap_update_bits(struct regmap *map, int reg, unsigned int mask, - unsigned int val) + unsigned int val, int shift) { - if (reg < 0) + if (reg < 0 || WARN_ON_ONCE(shift < 0)) return 0; - return regmap_update_bits(map, reg, mask, val); + return regmap_update_bits(map, reg, mask << shift, val << shift); } static int mtk_regmap_write(struct regmap *map, int reg, unsigned int val) @@ -49,8 +49,7 @@ int mtk_afe_fe_startup(struct snd_pcm_substream *substream, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 16); /* enable agent */ mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg, - 1 << memif->data->agent_disable_shift, - 0 << memif->data->agent_disable_shift); + 1, 0, memif->data->agent_disable_shift); snd_soc_set_runtime_hwparams(substream, mtk_afe_hardware); @@ -105,8 +104,7 @@ void mtk_afe_fe_shutdown(struct snd_pcm_substream *substream, irq_id = memif->irq_usage; mtk_regmap_update_bits(afe->regmap, memif->data->agent_disable_reg, - 1 << memif->data->agent_disable_shift, - 1 << memif->data->agent_disable_shift); + 1, 1, memif->data->agent_disable_shift); if (!memif->const_irq) { mtk_dynamic_irq_release(afe, irq_id); @@ -144,16 +142,14 @@ int mtk_afe_fe_hw_params(struct snd_pcm_substream *substream, /* set MSB to 33-bit */ mtk_regmap_update_bits(afe->regmap, memif->data->msb_reg, - 1 << memif->data->msb_shift, - msb_at_bit33 << memif->data->msb_shift); + 1, msb_at_bit33, memif->data->msb_shift); /* set channel */ if (memif->data->mono_shift >= 0) { unsigned int mono = (params_channels(params) == 1) ? 1 : 0; mtk_regmap_update_bits(afe->regmap, memif->data->mono_reg, - 1 << memif->data->mono_shift, - mono << memif->data->mono_shift); + 1, mono, memif->data->mono_shift); } /* set rate */ @@ -166,8 +162,8 @@ int mtk_afe_fe_hw_params(struct snd_pcm_substream *substream, return -EINVAL; mtk_regmap_update_bits(afe->regmap, memif->data->fs_reg, - memif->data->fs_maskbit << memif->data->fs_shift, - fs << memif->data->fs_shift); + memif->data->fs_maskbit, fs, + memif->data->fs_shift); return 0; } @@ -199,14 +195,12 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd, case SNDRV_PCM_TRIGGER_RESUME: mtk_regmap_update_bits(afe->regmap, memif->data->enable_reg, - 1 << memif->data->enable_shift, - 1 << memif->data->enable_shift); + 1, 1, memif->data->enable_shift); /* set irq counter */ mtk_regmap_update_bits(afe->regmap, irq_data->irq_cnt_reg, - irq_data->irq_cnt_maskbit - << irq_data->irq_cnt_shift, - counter << irq_data->irq_cnt_shift); + irq_data->irq_cnt_maskbit, counter, + irq_data->irq_cnt_shift); /* set irq fs */ fs = afe->irq_fs(substream, runtime->rate); @@ -215,24 +209,21 @@ int mtk_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd, return -EINVAL; mtk_regmap_update_bits(afe->regmap, irq_data->irq_fs_reg, - irq_data->irq_fs_maskbit - << irq_data->irq_fs_shift, - fs << irq_data->irq_fs_shift); + irq_data->irq_fs_maskbit, fs, + irq_data->irq_fs_shift); /* enable interrupt */ mtk_regmap_update_bits(afe->regmap, irq_data->irq_en_reg, - 1 << irq_data->irq_en_shift, - 1 << irq_data->irq_en_shift); + 1, 1, irq_data->irq_en_shift); return 0; case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_SUSPEND: mtk_regmap_update_bits(afe->regmap, memif->data->enable_reg, - 1 << memif->data->enable_shift, 0); + 1, 0, memif->data->enable_shift); /* disable interrupt */ mtk_regmap_update_bits(afe->regmap, irq_data->irq_en_reg, - 1 << irq_data->irq_en_shift, - 0 << irq_data->irq_en_shift); + 1, 0, irq_data->irq_en_shift); /* and clear pending IRQ */ mtk_regmap_write(afe->regmap, irq_data->irq_clr_reg, 1 << irq_data->irq_clr_shift); @@ -269,8 +260,7 @@ int mtk_afe_fe_prepare(struct snd_pcm_substream *substream, } mtk_regmap_update_bits(afe->regmap, memif->data->hd_reg, - 1 << memif->data->hd_shift, - hd_audio << memif->data->hd_shift); + 1, hd_audio, memif->data->hd_shift); return 0; }