From patchwork Fri Jan 4 20:27:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yizhuo Zhai X-Patchwork-Id: 10750043 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 D88F914DE for ; Mon, 7 Jan 2019 07:07:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C609028712 for ; Mon, 7 Jan 2019 07:07:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B855728882; Mon, 7 Jan 2019 07:07:23 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 182E928712 for ; Mon, 7 Jan 2019 07:07:23 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id CF4DA2679A5; Mon, 7 Jan 2019 08:07:04 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 69791267C2C; Fri, 4 Jan 2019 21:27:40 +0100 (CET) Received: from mx6.ucr.edu (mx6.ucr.edu [138.23.62.71]) by alsa0.perex.cz (Postfix) with ESMTP id 85175267B50 for ; Fri, 4 Jan 2019 21:27:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ucr.edu; i=@ucr.edu; q=dns/txt; s=selector3; t=1546633659; x=1578169659; h=from:to:cc:subject:date:message-id; bh=dVeo+lqbfDbwmjZVwas2MgBddAFiC9twLCj5ra9dt9k=; b=Mq0J62Wqm3I5SElmu2Vmbv+jiSWpvyp72uX+BYk8O/xkhlY2Vk1NabDt EiBffBXADOOHx5GvQ0gNfal8Er5K5bpht6553OdARXwsh0XOe3gSAxKBw l1oGu+ohEy772XjKbj09d3rmSoHYkyxsQ81737ut/LYAyFj09P+CroZxz hVHCujHh+ESPFTFIjTXsnqwitlBN7h3xnqz3xGK1hRCWlAxqqC7WHFAKH I8WiVlso0vTH9hM2/+riKV0CI8mnGaYwiaEmFK0RtGlZZjLBwdjNL6+aj 7TePdY3IZLtiI/WejS2GvLltfWEv0Kw7R8I5VQmZ0ZGSz1eOIcKBgJkMj w==; IronPort-PHdr: 9a23:u63qBBNmIpYw6pkxZwcl6mtUPXoX/o7sNwtQ0KIMzox0LfT7rarrMEGX3/hxlliBBdydt6oUzbKO+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxlLiTanfb9+MAi9oBnMuMURnYZsMLs6xAHTontPdeRWxGdoKkyWkh3h+Mq+/4Nt/jpJtf45+MFOTav1f6IjTbxFFzsmKHw65NfqtRbYUwSC4GYXX3gMnRpJBwjF6wz6Xov0vyDnuOdxxDWWMMvrRr0vRz+s87lkRwPpiCcfNj427mfXitBrjKlGpB6tvgFzz5LIbI2QMvd+e6LdfcgBRWpAWMZRWDFKDJ2lYYASAeoBPPhXr43gqFATqRezCxWgCObpxzRVhHH5wLc63vwhHw/YwQIuEdEAvnPPodnpKKsfS/y5wbPUwTnfaf5dxDfz6JLPchAkufyDX7NwcMvRyUkyEAPOk1KdqIzkPjOVzOsNsnSX4/ZuWO+0lm4otxtxriKxycgxl4nEn4QYwU3H+yVh2Is5O8G0RUphbdOnEJZcrT+WO5Z5T884Xm1lvC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,439,1539673200"; d="scan'208";a="17718286" Received: from mail-pl1-f198.google.com ([209.85.214.198]) by smtpmx6.ucr.edu with ESMTP/TLS/AES128-GCM-SHA256; 04 Jan 2019 12:27:33 -0800 Received: by mail-pl1-f198.google.com with SMTP id 89so27818288ple.19 for ; Fri, 04 Jan 2019 12:27:33 -0800 (PST) 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; bh=KIRoQOlFmlmxA8eKEGFEBWnDpcFgN9v4YUYbB67RaLE=; b=Gs/gO1Kq7CExqgA6O/xWHySHJMBoAbRnerWBVg4CUn0V/ZlwNPpdQyRlCCa4zqIkXb ovzUDCkLz0lbqXMkWqo6uDGppVS1IA8O7pnXOdS8sUOdIxw7TjaMjmi1/R70lRR+t0y1 1RBWFDgEZZprlovjI6JMdiETlJQEverCBao2LCfjdvcZDuWJoKF0n4vvhFn4VqRgvfrl yo+hemv2fIVpwTju/2KypoYwZOvJi8qiN49cyzNu4WqwHbbSAiXtoalI5S0eJAjIPmdM 1KkWLwy9V9eKHi3++8iZm+ooEAfoesyIeRM8loAPajxFWCt6tF+VP1h/r2aFxYsxB77N f8Eg== X-Gm-Message-State: AA+aEWbq7whtfcue5iwgamnWOtOxdvkwiqtO84ZE1CxnU3ov/2gwkbwG avZ5dPOwNL24/iuLJJqYv3JN4w111eM2KFkVcyfcqPBlH73sIqK+sT7S4ruCVw7FJd6nh3Sl5xv EHeUYTwG7sABnil4aizOK9Y1m X-Received: by 2002:aa7:8045:: with SMTP id y5mr53236012pfm.62.1546633652828; Fri, 04 Jan 2019 12:27:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/W03SynDHQ7y9cEWoVQUJakgQvJ8HKSIcPJakWCKASa8I69A1aWyyaXh3EHx3P+oMn518anoA== X-Received: by 2002:aa7:8045:: with SMTP id y5mr53235987pfm.62.1546633652339; Fri, 04 Jan 2019 12:27:32 -0800 (PST) Received: from Yizhuo.cs.ucr.edu (yizhuo.cs.ucr.edu. [169.235.26.74]) by smtp.googlemail.com with ESMTPSA id t3sm70447440pgv.31.2019.01.04.12.27.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Jan 2019 12:27:31 -0800 (PST) From: Yizhuo To: Date: Fri, 4 Jan 2019 12:27:08 -0800 Message-Id: <20190104202708.14759-1-yzhai003@ucr.edu> X-Mailer: git-send-email 2.17.1 X-Mailman-Approved-At: Mon, 07 Jan 2019 08:06:57 +0100 Cc: csong@cs.ucr.edu, Oder Chiou , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Takashi Iwai , zhiyunq@cs.ucr.edu, Liam Girdwood , Yizhuo , Mark Brown , Bard Liao Subject: [alsa-devel] [PATCH] ASoC: rt274: Variable "buf" in function rt274_jack_detect() could be uninitialized X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In function rt274_jack_detect(), local variable "buf" could be uninitialized if function regmap_read() returns -EINVAL. However, it will be used to calculate "hp" and "mic" and make their value unpredictable while those value are used in the caller. This is potentially unsafe. Signed-off-by: Yizhuo --- sound/soc/codecs/rt274.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/rt274.c b/sound/soc/codecs/rt274.c index cd048df76232..a2c1a6df8df6 100644 --- a/sound/soc/codecs/rt274.c +++ b/sound/soc/codecs/rt274.c @@ -353,6 +353,7 @@ static void rt274_index_sync(struct snd_soc_codec *codec) static int rt274_jack_detect(struct rt274_priv *rt274, bool *hp, bool *mic) { unsigned int buf; + int ret = 0; *hp = false; *mic = false; @@ -360,9 +361,15 @@ static int rt274_jack_detect(struct rt274_priv *rt274, bool *hp, bool *mic) if (!rt274->codec) return -EINVAL; - regmap_read(rt274->regmap, RT274_GET_HP_SENSE, &buf); + ret = regmap_read(rt274->regmap, RT274_GET_HP_SENSE, &buf); + if (ret) + return ret; + *hp = buf & 0x80000000; - regmap_read(rt274->regmap, RT274_GET_MIC_SENSE, &buf); + ret = regmap_read(rt274->regmap, RT274_GET_MIC_SENSE, &buf); + if (ret) + return ret; + *mic = buf & 0x80000000; pr_debug("*hp = %d *mic = %d\n", *hp, *mic);