Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5015239pxb; Sun, 7 Nov 2021 03:25:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJyd+0Ke1rBGl336PBjugRm4N8mpcMQqm7HOcIs0glH+OwSUPkycojEnaJph6EPFkIbHT9DA X-Received: by 2002:a5d:964e:: with SMTP id d14mr8057978ios.45.1636284343511; Sun, 07 Nov 2021 03:25:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636284343; cv=none; d=google.com; s=arc-20160816; b=jxphzIxIQlM/v27fFbDzbB2ksdfbRMhUOLl3tNNCTZIah7KQXUruxUfty2NIdkjMVj Yui4baSvGaa2PEAEGU/O8aM43ROwXXUJ7ftQ1uRTYiGbsZk2COllQ+g2SPE/4Ta1f1c9 S2B/3P6hAT98pvvVqCcjPDqbNebjgHDDi9PVvwrYofMXNG+01ublR84u9Z2wRBCQVGxL dCnCXQimaaVLxA/GDOeF1ZMe1khThmf0R8xGh/ybC3VWamGuH19v5KSmNV/xiOaAoyOH R1qulZraN+sASpZaJzKbRrGVVRpm3Ks2ezPpKenmkXkIXV6ndtjL0K9/nwlNoUGo6uKC Fzqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XZQ75wWFyM5Gecc77Q2zBq9LYat0h4SleZlOYKg3r2A=; b=kSGmDv2pJO5BKQJ2OSngBUBO5KffqYgPdVLKFYdkFppRg8zc7WnrQrMTIHT9+7pTf+ Xz8XEMXSrywxUYJgKM+SVn3cCucprhhTgf0DdwHlO+ozZ6QYmxZm/3RSYE/vh2nPGgH0 O3y6RriRaM6SAwthDAUDmjCeo9Af3siK0iyN9h76lf8xy4J7ZltwNBYXClMvdtNsEElT N78peqmOCnQdCr13nyhlaznPH6h8u3AGipIazyATaf/Qnv8T/nXaHVfFeI7HV/HxPplC JMs9gGKTR4qiKy0w5405pxi0uEtA4mIh8h8eUl3MA9mRRH3KUYUVHAAOp52b7en0bNai BZcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="UyeIFI2/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p7si29438898ilo.4.2021.11.07.03.25.31; Sun, 07 Nov 2021 03:25:43 -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=@gmail.com header.s=20210112 header.b="UyeIFI2/"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234551AbhKFWGL (ORCPT + 99 others); Sat, 6 Nov 2021 18:06:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbhKFWGL (ORCPT ); Sat, 6 Nov 2021 18:06:11 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FF0AC061570; Sat, 6 Nov 2021 15:03:29 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id v23so3450945pjr.5; Sat, 06 Nov 2021 15:03:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XZQ75wWFyM5Gecc77Q2zBq9LYat0h4SleZlOYKg3r2A=; b=UyeIFI2/YLVZ5V0Q9lZG+VZoyj7ASuLKXbbl9JpWXc2NwLtxs1/+modnYvy6pATwwR rEyq5MfKdyXgyAhA2BSYoBanWjTbf02QUjpeoCrVekDDxWOKq0JxGA86itCdXIq4IUOa LupLzQoZ4Ov8aUFbgRTQv1coMWJpe7IBJdYHCA/eNc0opDpoboej1RFVepY2jWrxu2wH 5SK7HUEQ0mcfTJwF1RPVah6FBg5vb85fjZ5McYPjDJzmboPj8t7il2DWnWyiVsmec3sQ ZIHQdw+UhzwgOcb9Fv6UFDgxig0IhRa4GUUi/JLSITB5MrnfMsjaKm6Z/ka/OR8tA918 nQbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XZQ75wWFyM5Gecc77Q2zBq9LYat0h4SleZlOYKg3r2A=; b=3MI9Sc45mY17R1qokMOKhJyUe1T/z4o4Vp71Q3ZQxhI+QnSvw+uXJ4ipn3xM4Em4iv BGSTjQeRSC8zTC+Qc0l8niTtc1SMpFA0ESQ/U6P1DvaAeKaW8IsWzayVF5pjc5fTsE2C fvDNjMWHQ+APkTsa6VQCiAhJbxq7nTPoM3asyIZflFlFy21yK4958gc1LQ2tCg//DWpL UnnRQkgRbtKttCmVaaL+T76b1qcmpl/Ii0DAVbV8HN4qRKXuXX96wVBRbaaJDK2LzT4O 8x4V4WkhlbMcFsJBinbPD4hwXQHWcKxH5hPU3FRwveBkFzC/V6k8i9z8Jw5fFhpUkd01 laYw== X-Gm-Message-State: AOAM532LWVIH8EAfd/RXDPWS8yCzaC7FG+xI+xthAi9/kL8mLYJAmkqD IjuwDGIuBlECwdcER947nJg= X-Received: by 2002:a17:902:7107:b0:142:5777:fb61 with SMTP id a7-20020a170902710700b001425777fb61mr8434164pll.59.1636236208475; Sat, 06 Nov 2021 15:03:28 -0700 (PDT) Received: from host-x86-64.. ([122.161.244.211]) by smtp.gmail.com with ESMTPSA id j6sm8628918pgf.60.2021.11.06.15.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 15:03:27 -0700 (PDT) From: Ajay Garg To: gregkh@linuxfoundation.org, jirislaby@kernel.org, andriy.shevchenko@linux.intel.com, kernel@esmil.dk, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: paskripkin@gmail.com, Ajay Garg Subject: [PATCH v3] tty: vt: keyboard: add default switch-case, to handle smatch-warnings in method vt_do_kdgkb_ioctl Date: Sun, 7 Nov 2021 03:33:15 +0530 Message-Id: <20211106220315.392842-1-ajaygargnsit@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). 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 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. 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..b83e7669658d 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -2090,6 +2090,12 @@ 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); -- 2.30.2