Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp735714lqe; Sun, 7 Apr 2024 01:07:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpfWPRb5PUyNk7eyjZN3tnMPcqTsrtITCm0PijzB2RnEt1FcL1teQGgox32U5iATXll2Pg2xSxcfFbbCLrc8aVkAibFXvNlWWH4+jMjg== X-Google-Smtp-Source: AGHT+IFMHCgGIDFM0njnMPyIMGz5faqkxgG6jtGGv692e/eB8J2PAiffFB6leQ/q4MWhtYjDbRW/ X-Received: by 2002:a17:90a:d805:b0:2a2:838b:7dec with SMTP id a5-20020a17090ad80500b002a2838b7decmr354622pjv.24.1712477247305; Sun, 07 Apr 2024 01:07:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712477247; cv=pass; d=google.com; s=arc-20160816; b=NAqLoyaL6OhkSxwbWVA6I8E/EMe+ZtcSQHwkzsh5Wk6B1GpB3W0qgQzuWbkoYIt+/W 9Zh59hnJqq6D8haEIeK7Q51kQQPkkt6OHsvOGnmj+9dWM52lhkchENj7k6pu2sO1LZeM 6sf1/ejQABp/MG2z2yH/9qBj8OTN6+qwh98+BOy09RJbYaPw/PniyEuTzM38IvLJOQKJ 7pB1VQINinaYDRPK54aahZT5cjTRSoT5lk1WwA86Y4dKeI7s2c13kjuHE0POH+WjHnCd jk6bZcCaNs7ith8qBX7ywmKLIOpAZtObg1AuDCvhiKF/QF66QIQ51IIBXDcX0Qd8srao 9wqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=jHRwBHxn0oc7UK384XKn6F49yYwWNuwEXuLNUt2jUsA=; fh=i/9cI0eQNLkbt2hISimcqRm69k4MNaR3OtkUtv4Nbkw=; b=wpOFo5o8dCw7ObjKbCoatOAF8lSIshBnbu9LF9fi5riTbJdlaWub7GTqKfFQlCf+oV mnmicC6KBdj8P+NpXuiSGrB5mjv49nTW2fLLc/EZ6LQlF58A81baxIFNNJSlsz6JF795 wRfvc3CojHjOgXBzadAUrKdnEW+4EZ3QR/HvSBzea5Av3WVQWa178vW4/GD3piLSJO9i 1oDrUVS1O3Z08fE7O1kwDSlmRpQiaPfx9BvDFQzeX/9XhnkO23mU9a9uuBxOFyAnhJuI E0rt9edhLEZQM7HTtqS7HatfHrz16LGwqq4uvLURttCg2Kev6GLKXGxsk2D2Sqb8lQ2y 4aZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E1Yme6dj; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-134244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a1-20020a17090ad80100b002a25a833cd5si4355956pjv.97.2024.04.07.01.07.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 01:07:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E1Yme6dj; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-134244-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134244-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 029A9282C11 for ; Sun, 7 Apr 2024 08:07:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D47F17996; Sun, 7 Apr 2024 08:06:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E1Yme6dj" Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 779B511711 for ; Sun, 7 Apr 2024 08:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.66 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712477168; cv=none; b=lc+cTfH9+0Bi8LO4Vc5S7U+x6glbIx/GcpUemMOjsCwtb0QtaLdoFSPnpacG2KgVpTcZoHgCVR9vzc6EUZL10LSRx+AKVoYEukiRhVzmui0BMOLPglhtG4aep7V5tIZeEHlM2Q/AtDHzDiKSbfZsIxB8hwjBwsafju09QoYf9Yg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712477168; c=relaxed/simple; bh=Rgb7nDRXj9MupxIRPzx+m7bzOmhCyq6njAcjkgSTuqs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=OA4uOs9iFTmCW4Ehvnqw59CAKD6sd2DxY41P3fCWMavbeFi8rV0Oe7Ld63IfhMZYA6IeqdSiQwdUdkCgVF+mwKchk7r5wrean+H/IUesjJPEXiHsjSRvbTDUbRaj6LRwkc6f5pighyi6rAN1Ev1k8meok/ZPCY5lw7QP5dlfc4E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E1Yme6dj; arc=none smtp.client-ip=209.85.216.66 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f66.google.com with SMTP id 98e67ed59e1d1-2a2c9903ef0so2439920a91.3 for ; Sun, 07 Apr 2024 01:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712477167; x=1713081967; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jHRwBHxn0oc7UK384XKn6F49yYwWNuwEXuLNUt2jUsA=; b=E1Yme6djx2dertv4qoU0riiTlkw0kHhSwdRBDmKYeNuHL7py1DO5zMU6cgCLvfnLEu WrzKVfOrQqLDYrQJOpUjzB/kcmrwdEfaDMpuq0TiQLwagLHhuYKJixYIiBBQ0kNnxl+G Ht+/2CJIPNXW9iGIrgMFkkTxrwKQYWUCj+iXKoUYJ+H+XIXMZ8/TspJCsfsOEKKSHTub AhS+EdI4YYliXHkbBvgWuWvH0C/IgawfCS91jkHGcOwV7fq1KoFSUfUJkJCc42vyTfcK crV4MUutGe6Lf4YBbcb+2TISM4W7BkrOckxVDbK+YooaQWB4maF6TV0FRJ1mF5/3TnGv V3rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712477167; x=1713081967; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jHRwBHxn0oc7UK384XKn6F49yYwWNuwEXuLNUt2jUsA=; b=N9iFTv2e8HriiAuCbfhnu5waXqipIdu3QtS3gBeCe6Q/UcJICM8Gnf5PMgYhN6jHOy zJ/8svPZkyER/YY/8N7NRqW1cz9Xlk3yl2RpqYxJry52UFED0bR0HtQvdQc4ixdQ9fLN JDvSvIa9LxVsm9Llaj9sRe7Z8d6ObEuQsM3anZvEpmNlhnKIqvWUwoZMAOUJ1+CPetZB AC+QqFgQ4gmfjFBZDIsElqlSDXez9uwilxJuqQXtBlxTOMnf7XLfGNrUOjO4R7Sa3Ky5 Sq3310hfcw/JqIruz+DIJ0snoskJOuau1Ym+aoFPsM8bwWRkroOe+YyRnhCfR5+CUOHQ b3eg== X-Gm-Message-State: AOJu0YxuwigMYryHzQdSuLH2xDHt9/Os6RJGR2vvW1NEqEKI7z9O2NIw HAYbmNe0J5KFKIYwKDrgf4EjirkeW8JwCuexpJBNJ4vSpQSDhDE+LGm9nvggEsgftUfI5j8= X-Received: by 2002:a05:6a00:1390:b0:6e9:74d7:7092 with SMTP id t16-20020a056a00139000b006e974d77092mr6789288pfg.24.1712477166675; Sun, 07 Apr 2024 01:06:06 -0700 (PDT) Received: from lhy-a01-ubuntu22.. ([106.39.42.164]) by smtp.gmail.com with ESMTPSA id s12-20020a056a00178c00b006e6c856c0f3sm4191297pfg.188.2024.04.07.01.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 01:06:06 -0700 (PDT) From: Huai-Yuan Liu To: sudipm.mukherjee@gmail.com, arnd@arndb.de, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, baijiaju1990@outlook.com, Huai-Yuan Liu Subject: [PATCH V2] ppdev: Add an error check in register_device Date: Sun, 7 Apr 2024 16:03:58 +0800 Message-Id: <20240407080358.8635-1-qq810974084@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In register_device, the return value of ida_simple_get is unchecked, in witch ida_simple_get will use an invalid index value. To address this issue, index should be checked after ida_simple_get. When the index value is abnormal, a warning message should be printed, the port should be dropped, and the value should be recorded, then jump to 'err'. Fixes: 9a69645dde11 ("ppdev: fix registering same device name") Signed-off-by: Huai-Yuan Liu --- V2: * In patch V2, we found that parport_find_number implicitly calls parport_get_port(). So when dealing with abnormal index values, we should call parport_put_port() to throw away the reference to the port. --- drivers/char/ppdev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c index 4c188e9e477c..ac5a93d39fbd 100644 --- a/drivers/char/ppdev.c +++ b/drivers/char/ppdev.c @@ -300,6 +300,13 @@ static int register_device(int minor, struct pp_struct *pp) } index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL); + if (index < 0) { + pr_warn("%s: failed to get index!\n", name); + parport_put_port(port); + rc = index; + goto err; + } + memset(&ppdev_cb, 0, sizeof(ppdev_cb)); ppdev_cb.irq_func = pp_irq; ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0; -- 2.34.1