Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3944673imb; Wed, 6 Mar 2019 01:11:14 -0800 (PST) X-Google-Smtp-Source: APXvYqw88Sz7ndPHGtAGh+WSRL8pYxWO5aCGiMhOII974/HWJf0zdpxbMgk/i9Wzd91RP6dnjk51 X-Received: by 2002:a63:1322:: with SMTP id i34mr5336170pgl.208.1551863474813; Wed, 06 Mar 2019 01:11:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551863474; cv=none; d=google.com; s=arc-20160816; b=RkyDK0PVoU7sYEuGViMVIIEwqADW70/o6KKIW9f9Y/XaY198CWh3hVy+xaq41IMXN8 oF/z5k3LQqgiNDUD3xzW7kI+YFXyzGZcq6wJjbADCFr3/x6p38t7Za8jvcyLzKHCBrD4 B5ErewgYJzYuHMFOI2ijSefR0HLyQ1Wr85zltwk35ViXF4+ds090f405nYvNTFCPtV6a ykzKFT2lTpHX8uBeeq9seHM2tkzKnSrdy8YMcRwcM+bP31Kmqh4dGzmJyVEHYWnzAu+O imfkOmjuNjiOV6/degKe7HnGryQXVqmuVUTKuCXoDalxXp6C75Ht3mQNF9nvmoFYbvdl Ep0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=wJOxMdrzk+4rw4ckkL08w9H5f7Ws6Ifi6+PYlrU/tu8=; b=PQNAWlTfHFvOcIxqHseWX+1RS2sRiKL1f5Squ2wIuhv0w2gtfGFW8VgfOuD9ZcdUOd I3+XrqrMMh5+UCeo7P9RCo3O+T5RkEx8T5MoOR5ZFB2BScSVEXGxGhRapeaile+5YteB SnlwE9dkW87qUMxFbWuPerg6ekGfmH1cWcf6CkKcpe7Br2jbhEHoTUaPkRQqRNtPG0we kEK2ixWDv2fdqIKwEoxvtdyQTt3hJXLRzRMuL/yDMv/39y1G0CFJmkpmekqFiepmVRAG fTjRGDUyE0gSGDv9EuJ3DvP1C0C7SInIA4QX4fN+3F2J6s3hB2R7kZxd23w+ybFmF1mF lVAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=ayg2KJ50; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7si966542pll.172.2019.03.06.01.10.59; Wed, 06 Mar 2019 01:11:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=ayg2KJ50; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729466AbfCFJKH (ORCPT + 99 others); Wed, 6 Mar 2019 04:10:07 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45293 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726391AbfCFJKG (ORCPT ); Wed, 6 Mar 2019 04:10:06 -0500 Received: by mail-pf1-f194.google.com with SMTP id v21so8065588pfm.12 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=P0Mu/DcpXX8SZjRG2YWSclI4cFcnYw1aBkPvfXohn/6igaA5dka6ixx7h3vswjX0/k r7FzHzuaPi3KmQtKQrPYroAEtRBe4f60ksPHxpV6VYTPqErR/R7CqVxbPK6bVZijZz/M h2aA9TZnjh2jG/lWmPCLsyT2ki42Ia3Y8vuWTrvpafGs2IlgmQ889zRrYTtJsHsGFgOH 5lt3yBGpROu0m0fmvNPJrrdtMZQLcpjEX3baA8L68xGQIKqD9nMC4tAj2AcOcbYVzoHH /Zlr7/4I1bXKS1cOi++tLiC6TB921RM07gkSj8Z1RWqUCnRA6ygnzZtkwFoY8VTR2BAm 0T9Q== X-Gm-Message-State: APjAAAW0IqJ1ErLenfVqnl7Tiy4ryQJZvqa5WLTiMqo3cL1Pkj30M5rj miYN7AZ9dqWmJ7UzUbBT15yiZg== 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 Cc: Pi-Hsun Shih , Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Matthias Brugger , Ryder Lee , Garlic Tseng , alsa-devel@alsa-project.org (moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-kernel@vger.kernel.org (open list) 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 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.21.0.352.gf09ad66450-goog