Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11555806ybi; Thu, 25 Jul 2019 19:08:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEbBtMeeLMdAzyuBPLIgS0CuhRknMuXeBXASNWY76o4fifCpz0U+WGSf7YCti8m0GZNj9L X-Received: by 2002:a62:e806:: with SMTP id c6mr19885071pfi.158.1564106929917; Thu, 25 Jul 2019 19:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564106929; cv=none; d=google.com; s=arc-20160816; b=BmObPf0ahcPP/CVwANYwdBHrvaTpKe+ztdJ29bVE4L8C50jZiP0n3aC4E5PvxTDbov St4DcCIMD0i9k5wNz1Vub1ic5ot1fFLiC5JWgLb4gEDJ1btkhCW7nYXCynPqF+S4dgtD tCs06o3rhaWDF34QT9TwEOxhfCdUMGpmrsxMIWQOjVljcs08qBvA7DLBgFs44R1C2EK4 nRGyIyUGUENh51JScjB0UWyWcwVrxmV+ZgRR6mkw8PGTRcRNY2+wGrgGjpsb4QEL6Ytw 3aBaKSz9hrOF9LgE4oLrEGC/vIGmzNWUb2e+kjNIOl1gpjH492e45/6ZSIxZo4KzPhsR toUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=cCr2oTsYVgIcEXvmtc7DlfGkkVp1TEqKVaiHx8VkY0g=; b=sw9E3kIyx4tZDjKjz7X8mnhl2u9GJ2VsoDKfH/Hr3bjWrkpsP3lmnnJfBFyPDMreE1 hEoX/LmbOf/6t/ZqRhK3D3vbjhofGaGNgmPKF/lxDaVsecFRD8WxFLfu5IKVN2E5goQ0 AcBE0RzhN9CgmN365zFyjW243e+wPQPOi2btqopm1uC4mJ1N8NF5anRwstKKFaf+WL34 IQMCPr8RlYHXXYAsrPjByJm0QaiRq2k8DlA25BA6DCwgM7tmtyFqCF3Ol3zJqeQCKFAj ltbIiKViAsZtJT4DN6eGFSQ3gLOUswe+KkaUAt1DBGUySgGG0RJtrsJgFA9QHIM+HgU9 z1UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hWnrUtBc; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a63si17649449pge.113.2019.07.25.19.08.30; Thu, 25 Jul 2019 19:08:49 -0700 (PDT) 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=pass header.i=@gmail.com header.s=20161025 header.b=hWnrUtBc; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725978AbfGZCFn (ORCPT + 99 others); Thu, 25 Jul 2019 22:05:43 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43679 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725867AbfGZCFn (ORCPT ); Thu, 25 Jul 2019 22:05:43 -0400 Received: by mail-pg1-f195.google.com with SMTP id f25so23941897pgv.10 for ; Thu, 25 Jul 2019 19:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=cCr2oTsYVgIcEXvmtc7DlfGkkVp1TEqKVaiHx8VkY0g=; b=hWnrUtBcKGH6duUC6atM3dFoGEBxjthHp13HPcOGJP3NvGrheBc5ubV7GtbnVrlUG5 w5xBX1gRoM47ksIqKWOFmWXir+gUPA0Gh2eTDKgpymSSztq9tcT/zBuN/n0rKnfOUuca qEBOAK2NsqTXHIFBuLpt5vzs2eCB9GmKpjPB+kgUHv7LrzqssPl1EAlagaMpS3cl11B5 Ddh3fFfxS5tzaLVHZMBeZDV1ZxTtRHvN9GoQhg8GT5xbsqmQxdkN3vS5pSlF/m8Bxnq0 02OcN90av2yFVbUIr4WKCyoepL+F+iRgaISztNFR+JUkamvg6b92qQRwAurdm9kPr6/f qF7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=cCr2oTsYVgIcEXvmtc7DlfGkkVp1TEqKVaiHx8VkY0g=; b=l8Vftz7JEsQCgsl/ycDEQPCT8ux2KArNh6ESX564solBEEBrWhN4r6RajInpWAuVZ/ bEnGfK53Vbsu0/ZsZxYh/vQG0UJ9dZNYDuJPHyQJh96nPhgI/rDDQFLFn73dZwC01lpP 0D5dRp4LCp+bEApMua7T5vZBJSXkMbNJiMsA1FLr00XExDJMnotcKRs2qCBMV7DPfx7b seCcaqxTjAEKuwayz0g6pHo2BlwokLPWZYUYl5XgRtBj6yJi5kPcAkLUXEYwvba3v8IZ 4vD07x/HyMTiJesuiv8e2LANoKTTi4a837SjxaMI58EWnfr/XhpFj3RtaOqBqTNx2gL2 2F9g== X-Gm-Message-State: APjAAAUOTQr36yECygdR9aYf9NDFpsDFnuM+qzZXQrZc1xONgE7QVVmB Hx/q58WaSyZ0eNBsnZBy2lIsL1IKOU8= X-Received: by 2002:a17:90a:4806:: with SMTP id a6mr96016852pjh.38.1564106742844; Thu, 25 Jul 2019 19:05:42 -0700 (PDT) Received: from ?IPv6:2402:f000:4:72:808::177e? ([2402:f000:4:72:808::177e]) by smtp.gmail.com with ESMTPSA id b126sm75007442pfa.126.2019.07.25.19.05.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 19:05:42 -0700 (PDT) Subject: Re: [PATCH] ALSA: i2c: ak4xxx-adda: Fix a possible null pointer dereference in build_adc_controls() To: Takashi Iwai Cc: tglx@linutronix.de, gregkh@linuxfoundation.org, perex@perex.cz, rfontana@redhat.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org References: <20190725082733.15234-1-baijiaju1990@gmail.com> From: Jia-Ju Bai Message-ID: <5ef03517-a52f-fe24-30e9-62466d4a1319@gmail.com> Date: Fri, 26 Jul 2019 10:05:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/25 23:52, Takashi Iwai wrote: > On Thu, 25 Jul 2019 10:27:33 +0200, > Jia-Ju Bai wrote: >> In build_adc_controls(), there is an if statement on line 773 to check >> whether ak->adc_info is NULL: >> if (! ak->adc_info || >> ! ak->adc_info[mixer_ch].switch_name) >> >> When ak->adc_info is NULL, it is used on line 792: >> knew.name = ak->adc_info[mixer_ch].selector_name; >> >> Thus, a possible null-pointer dereference may occur. >> >> To fix this bug, referring to lines 773 and 774, ak->adc_info >> and ak->adc_info[mixer_ch].selector_name are checked before being used. >> >> This bug is found by a static analysis tool STCheck written by us. >> >> Signed-off-by: Jia-Ju Bai >> --- >> sound/i2c/other/ak4xxx-adda.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c >> index 5f59316f982a..9a891470e84a 100644 >> --- a/sound/i2c/other/ak4xxx-adda.c >> +++ b/sound/i2c/other/ak4xxx-adda.c >> @@ -775,11 +775,13 @@ static int build_adc_controls(struct snd_akm4xxx *ak) >> return err; >> >> memset(&knew, 0, sizeof(knew)); >> - knew.name = ak->adc_info[mixer_ch].selector_name; >> - if (!knew.name) { >> + if (! ak->adc_info || >> + ! ak->adc_info[mixer_ch].selector_name) { >> knew.name = "Capture Channel"; >> knew.index = mixer_ch + ak->idx_offset * 2; >> } >> + else >> + knew.name = ak->adc_info[mixer_ch].selector_name; >> >> knew.iface = SNDRV_CTL_ELEM_IFACE_MIXER; >> knew.info = ak4xxx_capture_source_info; > The code change itself looks good, but please follow the standard > coding style. In short: please run checkpatch.pl, fix errors (some > warnings may be ignored) and resubmit. Okay, thanks for the advice. I will send a v2 patch. Best wishes, Jia-Ju Bai