Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4269155pxb; Sat, 6 Nov 2021 10:16:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhKX7iLardSaEDrhSVATbZDkYlsBjGNcYHLYIwEX1ppeZiU42WXgR2hJyx7whAhow4W0DS X-Received: by 2002:a17:906:ff47:: with SMTP id zo7mr35452936ejb.148.1636219011517; Sat, 06 Nov 2021 10:16:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636219011; cv=none; d=google.com; s=arc-20160816; b=Ujeenfm7+G7dqed85ToFA50OFkA5upZJ8MB4QwFSzRsGDRMFZdsrTELgZ8wXAJB7db rkx3aD/bvRKyv27lvwnWA6688PPKqFHpOvOZeP7lq+v+21VNSmLuCvHwLwCcWjo7sPr7 wFdUpiNcuuGHaD1HRRppyOcLmafMu3eYRo5UTxxDMBaeDIAqtROuLJ8GcLdU+hoJ48Hd rk114u2xE9ceU0bG+b1fBqvXn2CP0Lt46sAJEUuCCYzBVFQMmPC8MEfc2A7ZIp5qPMsE 4ECCtBMIUF1LBWI3+LRgRXjh0sApe8tMPd6sGMFcDAcbW+PXlzpJhLGfAekJ9sFSyKH4 5dIw== 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=DDLHjXHgylqb+MPnHWavokSJXf5Zitf6xR+vNKKk64w=; b=mv72AIS77KU2K1Kia3x1/9d827rAT7SL0Fg1CdSmtpTb4tkdmFlNDs+BPTe5KGBHR+ a0rhIgspMvSSEI3mv5kd288nW09Pf+Y7uu319tcyojD111at6QHNU93M8TvqBUAzYKsH 3tQJC13OWh4YyaZZLM4L3FuNTAZ1REj6/pRC23GPrx9PKUVMisNR3TwVCCFPGUTrtUgB p5W6KA7DHbms/rjbVCzCK/v7+TY+Wn6PArdl4nyzDx9Pz7copFMpXgZr1hpjUUgeOHo8 WXdRR1ASFeGdANdFxrm12dudTvCuiuUZCXetKwdSF5ghDwJtPaTGnkwJovxWhJQ4in4y IygQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=KkX7ojqL; 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 h19si19765592edt.391.2021.11.06.10.16.26; Sat, 06 Nov 2021 10:16:51 -0700 (PDT) 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=KkX7ojqL; 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 S233768AbhKFKnr (ORCPT + 99 others); Sat, 6 Nov 2021 06:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230219AbhKFKnp (ORCPT ); Sat, 6 Nov 2021 06:43:45 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DBA6C061570; Sat, 6 Nov 2021 03:41:05 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id gb13-20020a17090b060d00b001a674e2c4a8so5148849pjb.4; Sat, 06 Nov 2021 03:41:05 -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=DDLHjXHgylqb+MPnHWavokSJXf5Zitf6xR+vNKKk64w=; b=KkX7ojqLTHG3tu8JhGZnyppF7EqmI5mQ3HVzpNrDEzvfDqvDp1V54IK6wWrFQaNoxj 0YBrPtcAAZF8B1PUdH6hV5Pd5qf5yNUyxZcBEjCkRl3PJMip0u1v7RhW4GlywZLGXgv+ J9cnQ3csYmaf4tADX476QMlV9Azs6B7qZ/PpQ2cYI/a/BVplPG7jFiROknBixasZpoUm fgZjd1fSIGKUeHDqbZnBWbjKmal/iRoBkUAgmS7l0GODALwI1gMmlfZcbtUMEwTIN173 /+wgjuge3Hz8CCrN0EiHnAQEEX/QtILudfh3RJsjxHX/pfsHiJ2bGK/9MHMJ39VfFKYs nK7A== 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=DDLHjXHgylqb+MPnHWavokSJXf5Zitf6xR+vNKKk64w=; b=f+gQufmSVDWa2XIWfLaqCynXQuDERuObsGV6VbjAGMcSaeRi52KYLfQl5XpiQXvFzq niSjhRvBvLJxC5VfKbtrQrZMWN1zgxRzPNJVoK4IIbCjVi05zb9HV3iFRHeF8jFG/orw ftPyOR8+dI43fzGlYmWIU72yFY2THrpqf3EgEezxuq4ZFcpEWjpAu8JFQSFv0SS591bR xYbJooCM8Vzvr50nh5YkMxsvtZitO9U0HPqdLyFth+R0WV9suibhmfcNxMsgKy+e9Ao2 p+0OA761zXgdjKwTtrPVNiUoijzFO+/jx7LrFHcHTk/C090wyZlROoYrYJBv38Wql4EO dNEg== X-Gm-Message-State: AOAM532DAD9Ih1TAttkNeKazVNJ5WSpsjFXi6ELfSKWuukHXMxcLyMcJ GNj8BhjW6HkCAJGT4Ke6LqaPY07YJcA= X-Received: by 2002:a17:902:e550:b0:142:2673:d873 with SMTP id n16-20020a170902e55000b001422673d873mr19715297plf.5.1636195264147; Sat, 06 Nov 2021 03:41:04 -0700 (PDT) Received: from host-x86-64.. ([122.161.244.211]) by smtp.gmail.com with ESMTPSA id e15sm673368pfv.182.2021.11.06.03.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Nov 2021 03:41:03 -0700 (PDT) From: Ajay Garg To: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ajay Garg Subject: [PATCH v2] tty: vt: keyboard: initialize "kbs" so that kfree(kbs) runs fine even if kbs is not kmalloced. Date: Sat, 6 Nov 2021 16:10:53 +0530 Message-Id: <20211106104053.98761-1-ajaygargnsit@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org v1 patch at : https://lore.kernel.org/linux-serial/YYZN30qfaKMskVwE@kroah.com/T/#t 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. For brevity, here is the background : In "vt_do_kdgkb_ioctl", kbs is kmalloced, if cmd is one of KDGKBSENT or KDSKBSENT. If cmd is none of the above, kbs is not kmalloced, and runs direct to kfree(kbs). Values of local-variables on the stack can take indeterminate values, so we initialize kbs to NULL. Then, if kbs is not kmalloced, we have kfree(NULL) at the last. Note that kfree(NULL) is safe. Signed-off-by: Ajay Garg --- drivers/tty/vt/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index dfef7de8a057..54155fc91cd2 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -2049,7 +2049,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) { unsigned char kb_func; unsigned long flags; - char *kbs; + char *kbs = NULL; int ret; if (get_user(kb_func, &user_kdgkb->kb_func)) -- 2.30.2