Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp848301lqe; Sun, 7 Apr 2024 06:47:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2rdqi2QTxU8wSdTCLepXiRt8vPyZD/GbZ4QVorHj0GIaoZRHvDi9sARbjaQdawZJxL0/WZ8WHylOYDWaUOT18kqBf5ydYnTTHjNgrIw== X-Google-Smtp-Source: AGHT+IGzW1WAn3m4mrZwUHjaLhC5s/BwaJnVOxjJbAvFOHjfWbTAqYC4yNazV+SLtQfm2WHBHZ4i X-Received: by 2002:a05:6a21:164a:b0:1a7:63ac:a3aa with SMTP id no10-20020a056a21164a00b001a763aca3aamr1460325pzb.30.1712497668252; Sun, 07 Apr 2024 06:47:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712497668; cv=pass; d=google.com; s=arc-20160816; b=j9Rj8NvQ2ee0W0IN7FCSVlY/0dEJ2PalAFOFVgDpAHQ/kcb+fIVF0A3G2OsX8yF90c lwZwNtSxbFIdbikvna44l32oYRiFPyG8pbGQv8m/tcoLhH0ArCk2Rg+e0iBOv/6Yx3+W OGg3XwSgrJR8hA6HkVKAS92weul27gmfs5tJLUtniAf4kuVLMe6VjIXOjlSI3MBzutb4 McwS967FKQ+m8ZaZeBdDe4hmJ5ktdK0V6faUMGZxm/hiuk86IiEpJQrpS8aPYScepUFC +ugsy+UQENNnHeP23nW6uqs0iHI8W0PVQatgrayVAeBTTTRgU/xzaHJEDzbb19j/97in Egtg== 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=1eplB7rHSkoFmDqIIBpZQgckLsHN14+8+C+N4HT8iAs=; fh=i/9cI0eQNLkbt2hISimcqRm69k4MNaR3OtkUtv4Nbkw=; b=k26yvIC0RcUyoFHYjgP3KBZtg2XfJV+JhPNM9y38lNWQ2bVO9HkThnKJR6YjjTGhyS KhN6MDmj3XwGxrdJqQEqPY/HCU2HWJDN6eJ/ed8eViY04hq//bjUBWUZNUjbwXTeb7Kb lls0b51cdvAiOpY+dgGEaLYxCEBNfbdeEydxOVpquRrc+29yc1T5dvPsprQG5aGwKb+x h4aXge34DVmRptqQbWoUEOQpfJBk6gcH+wGl5QlQ15e539bVwkl8REnatr2Cq3jY3AXP 44loctHxG7OBGAADdDrgO+aRrMHXdFER4hOxePdLC8Kxy52i4Bf7g4bdkgixKGmsHpGd /1Dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TLRTQknE; 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-134502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i12-20020aa787cc000000b006e69fdb9967si4592855pfo.3.2024.04.07.06.47.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 06:47:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TLRTQknE; 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-134502-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134502-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 86F4EB22A8A for ; Sun, 7 Apr 2024 13:42:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFBDA3B185; Sun, 7 Apr 2024 13:23:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TLRTQknE" Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) (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 AE9453838F for ; Sun, 7 Apr 2024 13:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712496185; cv=none; b=RNqpg1EQaDaNpeYWAS5tCJsPyg8lVuSqSks7lq2bJVEeVier+7XFW4MgPT2//rf7N6AavQy9upB/Fjma0LdrxUUf2ze7GTlbBzyh5uew9L4lR1PRA9tX1aCuCknzDN5rUgze5EQiS0PWFqQx+MymwLOkpS0ZOusrRqXJlh3k2Vs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712496185; c=relaxed/simple; bh=T6OMxDGBj6shnRpK6I/E3tiSw+Kcv040bGQQxvrkfCc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=LEgG+z+kFEsvK5YjTKgVv6tjSGGlt/5b3LnZaZv69wiPsMwuLme2Lzdj4g9W5z+9fxKlC5oEce0fArEsq5NVmH1h5bO5ot27yKv3ocxms4IezVlV+yESo53DMvVUZkTeF2MvYx/UeFy5jo2iW8yrGhD1x+ceAlUvpjzgzeRd/xk= 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=TLRTQknE; arc=none smtp.client-ip=209.85.214.195 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-pl1-f195.google.com with SMTP id d9443c01a7336-1e411e339b8so1639405ad.3 for ; Sun, 07 Apr 2024 06:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712496183; x=1713100983; 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=1eplB7rHSkoFmDqIIBpZQgckLsHN14+8+C+N4HT8iAs=; b=TLRTQknEI/2ed/IFVHxbkrVvkrLRFVb//sjEjJY6olffIkXIYKvAT6K47kQVN0qLoi N1bEgioqP171wJLx+qtScoIuy9VgfidtqTlbmDMhdp69WXuqXZB58GeDmze357eanQT5 /tPhFK8IHFoepOgWEh9A17T7vjVda5rarOnUaOpeG3UzPqUI0G4hDRh4byhCCKI7DJYC cHNCpXrT+JuGRHQeaKfLDAcg6kDmCrS1o5WfJrzARcZKjm+xiP2n70+C5PUV57tS21xT XIRABGoiQFJrc++UfKqneanevsNIEIm42QXLAAQ+bSfqnTxgouEUCS3a3W6PBSI7sFie JL8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712496183; x=1713100983; 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=1eplB7rHSkoFmDqIIBpZQgckLsHN14+8+C+N4HT8iAs=; b=uXqUU9nw1Rqf8kYWk5b4albBs7/PGnHaEx2MfyGe6B4NPrucP0TAhWVbh3X0m4vkX1 o9g4AJZt9fKsxFxlpFOtjjwfF2mXMUtNXqr3MfYaJM3FZo5aNFyeTDhkD7gp9ThRXaq0 2kjjWbmtJWzcURm6k6gGdcXuVTcK1OkN/Jlhy9MIl5cCEr0SDRjeAAnK2J4VKQ7VNLm5 ABl83llsbPj2IlMUOeS+0th84HKGNJW8MM/cuxUMOuk9FIfO2UIISLluWHmwPvI78agH e9BpzpVcIBQcpMtkOFDt09BQ2Uza0SHo1kJfFajmZscN9SfT6Y2lFqgjAXkmIz8kABwn ysCQ== X-Gm-Message-State: AOJu0YwCbyobzWSTM5aQwNr6dPyva9k55ikxJprSb5amP3x1qgt0HQL1 B1Jwy1wB6jUxflYNKBBMuNPFVEvd7NCEpdRdwSMHsAFM0A8tSJXfVcwR59LlSPBJxl8DCS4= X-Received: by 2002:a17:903:22c1:b0:1e3:df09:e1dd with SMTP id y1-20020a17090322c100b001e3df09e1ddmr4393050plg.53.1712496182936; Sun, 07 Apr 2024 06:23:02 -0700 (PDT) Received: from lhy-a01-ubuntu22.. ([106.39.42.164]) by smtp.gmail.com with ESMTPSA id q5-20020a170902c74500b001e2670c3406sm4910892plq.306.2024.04.07.06.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Apr 2024 06:23:02 -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 V3] ppdev: Add an error check in register_device Date: Sun, 7 Apr 2024 21:20:54 +0800 Message-Id: <20240407132054.12170-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. 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. V3: * In patch V3, we made some additional adjustments to the jump labels, making the code more concise and readable. Thanks to Christophe JAILLET for helpful suggestion. --- drivers/char/ppdev.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c index 4c188e9e477c..276db589b901 100644 --- a/drivers/char/ppdev.c +++ b/drivers/char/ppdev.c @@ -296,28 +296,36 @@ static int register_device(int minor, struct pp_struct *pp) if (!port) { pr_warn("%s: no associated port!\n", name); rc = -ENXIO; - goto err; + goto err_free_name; } index = ida_simple_get(&ida_index, 0, 0, GFP_KERNEL); + if (index < 0) { + pr_warn("%s: failed to get index!\n", name); + rc = index; + goto err_put_port; + } + memset(&ppdev_cb, 0, sizeof(ppdev_cb)); ppdev_cb.irq_func = pp_irq; ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0; ppdev_cb.private = pp; pdev = parport_register_dev_model(port, name, &ppdev_cb, index); - parport_put_port(port); if (!pdev) { pr_warn("%s: failed to register device!\n", name); rc = -ENXIO; ida_simple_remove(&ida_index, index); - goto err; + goto err_put_port; } pp->pdev = pdev; pp->index = index; dev_dbg(&pdev->dev, "registered pardevice\n"); -err: + +err_put_port: + parport_put_port(port); +err_free_name: kfree(name); return rc; } -- 2.34.1