Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp6320407pxb; Mon, 8 Nov 2021 06:47:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9wvC6G6n8WBJ7QZ2ZTb9cv9L/YkgNCfzozROEPh0LLJlFzNRR5CTnLn/BcIfblQ+CQuvO X-Received: by 2002:a05:6402:d78:: with SMTP id ec56mr221272edb.226.1636382833276; Mon, 08 Nov 2021 06:47:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636382833; cv=none; d=google.com; s=arc-20160816; b=02GDpHafLKl2COOpSUUZK7nvFPvLXXJ1BX5KzYg/7cDao1lAlpxs1+7M2pYMewKWFs fHhDY30R0iKaxVsm3V1GcZdncRYTbxDxzAHwp2XEI2xkV4qIJfOQuplQYSFtCYO2+GCe UrwdrTQGDLjh9skqFt4fEnfzcUU9hQS+N9pdK4gTk9QnpA3+yvikKqejCmYgr73epIIH A07D3I4iNCeyvcdvfPwL/zsyPNtYFAPK/YOg8sU4f38x5IM6bMu/cavE9jNyj7t6eCNd cHMABQyrDqpZh+uAJCZsRZtTHfADIYq2Qg5KFHZOk80CJZJ5LiO/0UlqGrdT4Mqlz60Y BP2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5waiE96cqhmZf5XyLcHS0SCve2xAMwChVxHqqa2enO0=; b=Xjmb+oUAISgzdevpJGCyZNVGZQzK9VdU9wsW6Rvo4MI6w70smvtpB9aDBv817tW/PQ +H+lJRSPSaM55b0RMLHL/zgOiMC5jzlqJIWpIJmuu1hNHPLzqIjrQZZtzc9i0ZT16sFR 9GmklgNEmu9erADfLNNugf8r7+xFTq8CFjnerj84MKgnDOaWTZ6o72mXuwFlvznxclyy 2WRMzkeWXnPj7R/GwxOJkv1AoHnc5jZNO8fDIWbOPZrNl27YehC41KL0fVNOP9rhE71R cHBUWgPwEbSTBl9/qVZjSRUm7dYgYhogblBs4/jI2HgDFApfAVTo2sPNUXTiCa11ZyBm hQVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tXiQvIp/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g4si16323088edy.503.2021.11.08.06.46.49; Mon, 08 Nov 2021 06:47:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tXiQvIp/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237172AbhKHJoe (ORCPT + 99 others); Mon, 8 Nov 2021 04:44:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:33860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236838AbhKHJod (ORCPT ); Mon, 8 Nov 2021 04:44:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D5B1961242; Mon, 8 Nov 2021 09:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636364509; bh=KubNRzNxhXVYig4fprNmbCEDI0o1MB2KC5bqwRxBdsI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tXiQvIp/aMZhEW+2/cYq+GecvOAMtof+uzLEZJPzHvylPVEA2Uqq9CHCHwGfWhi1k Yk4NhLWGUbGlb/4uIrYpDtMsfdAqnfQedlb/bcfOIlIocFZFsG0RaY+ugq/FeMFVJm EqsjmdFwO65Hw9kiSdYj6L+uutw+CNzd9ljGNT5J7n7BCY9waoQUPYzDwVH9robrpy AcOnHMDijykttGdwyiSpR3R9fXGTINCP3fiyXr8fWPFY2YLCVyAe8rvLP0Hare3nlc TAN+qUOflI3jZsILRsr0hIrJuYm91tQZwnpNfmQf9blfIzVBSDR2bCLgvzfW7wW/Rh 0KzhQAQDa72GA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mk19u-0003VH-7U; Mon, 08 Nov 2021 10:41:46 +0100 Date: Mon, 8 Nov 2021 10:41:46 +0100 From: Johan Hovold To: Ajay Garg Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, andriy.shevchenko@linux.intel.com, kernel@esmil.dk, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, paskripkin@gmail.com Subject: Re: [PATCH v4] tty: vt: keyboard: add default switch-case, to handle smatch-warnings in method vt_do_kdgkb_ioctl Message-ID: References: <20211107031721.4734-1-ajaygargnsit@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20211107031721.4734-1-ajaygargnsit@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org First, please fix your patch Subject which is way too verbose. You should aim at less than 72 chars including prefix. Something like "vt: keyboard: suppress smatch warning in vt_do_kdgkb_ioctl" should do. On Sun, Nov 07, 2021 at 08:47:21AM +0530, Ajay Garg wrote: > smatch-kchecker gives the following warnings when run on keyboard.c : > > vt_do_kdgkb_ioctl() error: uninitialized symbol 'kbs'. > vt_do_kdgkb_ioctl() error: uninitialized symbol 'ret'. > > This usually happens when switch has no default case and static > analyzers and even sometimes compilers can’t prove that all possible > values are covered. > > Thus, the default switch-case has been added, which sets the values > for the two variables : > > * kbs as NULL, which also nicely fits in with kfree. > > * ret as -ENOIOCTLCMD (on same lines if there is no cmd > match in "vt_do_kdskled" method). Not sure how far we want to take the suppression of false-positive warnings but at least this isn't the right way to do it. > Many thanks to the following for review of previous versions : > > * Pavel Skripkin > * Andy Shevchenko > > > Signed-off-by: Ajay Garg > --- > > > There were discussions previously, and the current patch is the > result. > > v1 : > https://lore.kernel.org/linux-serial/YYZN30qfaKMskVwE@kroah.com/T/#t > > v2 : > https://lore.kernel.org/linux-serial/CAHP4M8Vdj4Eb8q773BeHvsW9n6t=3n1WznuXAR4fZCNi1J6rOg@mail.gmail.com/T/#m18f45676feaba6b1f01ddd5fe607997b190ef4b9 > > v3 : > https://lore.kernel.org/linux-serial/20211106220315.392842-1-ajaygargnsit@gmail.com/T/#u > > Changes in v2 : > > * Changes as required by scripts/checkpatch.pl > > * Checking whether kbs is not NULL before kfree is not required, > as kfree(NULL) is safe. So, dropped the check. > > Changes in v3 : > > * Using default-switch case, and setting the variables > when there is no matching cmd. > > Changes in v4 : > > * Removed braces for the default switch-case. > > > drivers/tty/vt/keyboard.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index c7fbbcdcc346..f66c32fe7ef1 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -2090,6 +2090,10 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) > > ret = 0; > break; > + default: > + kbs = NULL; > + ret = -ENOIOCTLCMD; > + break; > } > > kfree(kbs); Instead, move the kfree() into the two cases blocks and initialise ret to 0 as is done in several other vt helpers in case a driver bug ever causes them to be called for the wrong cmds (e.g. instead of sprinkling WARN_ON(1) in all those functions). You may want to mention that the kfree warning was introduced by 07edff926520 ("vt: keyboard, reorder user buffer handling in vt_do_kdgkb_ioctl") which moved the shared allocation into the switch statement, and perhaps also mention 4e1404a5cd04 ("vt: keyboard, extract and simplify vt_kdskbsent") for the ret warning. Johan