From patchwork Thu Dec 21 01:20:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp120072dyi; Wed, 20 Dec 2023 17:21:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgMKsVv6pz/KoCa/3N6+4DzdGdt88Xxz1Hm17R9Mr+c0ZJliIFuMwnnFZHSPMdnfcSNMf7 X-Received: by 2002:a05:6a20:e120:b0:194:fd7d:ebcc with SMTP id kr32-20020a056a20e12000b00194fd7debccmr518712pzb.91.1703121690891; Wed, 20 Dec 2023 17:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703121690; cv=none; d=google.com; s=arc-20160816; b=L1ft6Izz/CqTWk7rNFZj0yZ5+OPbFA1m2yCU2VXPfUnE17TLS8rN/KXQdTL3JRjQCQ SEihEdF/ZqgZbU12eFp3kZHGXz+3WRjb6a+Zq7EuJnlmR1PcoatQrWOd7fNkHu557Krf bVDjQsm/MtX3qz2BxnTuMt1fDdNs/klM8DEDVZ59xX5Dx9vfT+lZ2FfXLmF476dF910Z cGwvurBaGDTXYVS8QYvtxX3XYaPYks6R5ob4ry2AlzlxgYUuJ7tWqrvkKbJetCPUAl1k 4fX6IXBU65HVjMn/SPz4szRLHDZfpNe7orWUohUSVBCn6CJN6JXlutZ7r6BEVBytKhet EnJA== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dLcenJ/GoxU7aCIQv2oBr9pxlEYNKaNvVPdm4SRt55Y=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=gbVfbSxnkeObsPqQ0nrldyqBwmLWdY8vkh5T1xIoIcPu7bV55NtICEmdtyddqbkBo1 sS4VIF/2m8CG/4xmlCx0ZeV8rlh3dX3m0Q/BJX3G40yMOSwLTgYyt7cQzAg+hbtAawYZ JblL5r8vuUGphitP8R14pZK26tXrPuEVAbPLX24XuB+2W/35M6qNobYu2ZbkDlr2kZBC Lnt5+avmB8W0KslBg2hRl7DJBY9UNvpKbJU6WmTK2mlRoFEHrJUUYy84l6XwzBKyeOXp 00H6Yft9kX0J27zRJn2kB13uIditCqeFIukUNNDlH5cWDKWgsOvGgrQ0RczZwR+RtO07 3W8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GsAZ+dax; spf=pass (google.com: domain of linux-kernel+bounces-7719-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7719-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q18-20020a656852000000b0057942bfab4dsi645685pgt.395.2023.12.20.17.21.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7719-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GsAZ+dax; spf=pass (google.com: domain of linux-kernel+bounces-7719-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7719-ouuuleilei=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 EB136B23AA1 for ; Thu, 21 Dec 2023 01:21:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AB09291F; Thu, 21 Dec 2023 01:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GsAZ+dax" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 142A63C1E; Thu, 21 Dec 2023 01:21:13 +0000 (UTC) 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-pf1-f169.google.com with SMTP id d2e1a72fcca58-6d741fb7c8eso295543b3a.2; Wed, 20 Dec 2023 17:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703121673; x=1703726473; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dLcenJ/GoxU7aCIQv2oBr9pxlEYNKaNvVPdm4SRt55Y=; b=GsAZ+daxbBZTZMEMcH66YqMkzeelDrlYtZ0dd0+jcDh+X5cuXMzvb8oypy7IyBzrG5 MJV0O1tML/Snl8EytCfYb2NnyWZI2SWEXjGKhzxGCDIpC78kmuZkZJZ7pebFPx3BzR7N EPSzSET7cYNTN5nMDYkChZWyaBWt9ukIosCSTPktXqsEqXgv+Cckizjl34z5KkLYA1ka WOrzVaXZwTYZg+bdlSXN8e/vEzwjn2iDe7YsB8ZemWlbOHDrgJafAalkJfBCSq4ChdLd H//GKNFRaDMm432hUkzPYSo7EeTyvoJAurOQA9WsdHSOu9POKBANwpK+qKCvQcSIInZE QvIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703121673; x=1703726473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dLcenJ/GoxU7aCIQv2oBr9pxlEYNKaNvVPdm4SRt55Y=; b=cl4C2nZA90GuF3ALYlN9ZFPiKUTzw6Yp5dztFp4oQ/iiD0f5G7Bv4GqVlotcFoFlRi tYNYbPpUD/UxG4wVH9mVYswg2z3Wd48GYXlC9j28yZ93lFCG2e3cUDF7DNy0Ya6HoFCt VyCH83znfbc/3sL5DuEryM1W5IS5Mi4nynopvGraT7GJo/fnVfBtJ8MGeC2kBI0Fai0L hMnJ34aPFA3EVNTraDPmj/xagFcWNDGMOP5OPPiOiZWv6nVhXL8uiXiAfticA4qzX3c+ sccFXz43c6uyPP8l0d3uFV+c9courSO+MFeZU4V30zNPrULBo2gxPVxxGn/oSaoEzgDQ TzvQ== X-Gm-Message-State: AOJu0Yw6n6jdSduVPg/NPr7zu0F2u/+1J5/OBHfjwdntX4LS5sotL5Ed Jp6LN7s72CpyujUEhuag672SP+D53kQ= X-Received: by 2002:a05:6a00:f8e:b0:6d8:cf8e:e627 with SMTP id ct14-20020a056a000f8e00b006d8cf8ee627mr5338333pfb.37.1703121673191; Wed, 20 Dec 2023 17:21:13 -0800 (PST) Received: from rigel.home.arpa (60-241-235-125.tpgi.com.au. [60.241.235.125]) by smtp.gmail.com with ESMTPSA id x1-20020a056a00270100b006d088356541sm375959pfv.104.2023.12.20.17.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:12 -0800 (PST) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, andy@kernel.org Cc: Kent Gibson Subject: [PATCH v2 1/5] gpiolib: cdev: add gpio_device locking wrapper around gpio_ioctl() Date: Thu, 21 Dec 2023 09:20:36 +0800 Message-Id: <20231221012040.17763-2-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231221012040.17763-1-warthog618@gmail.com> References: <20231221012040.17763-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785852529905532814 X-GMAIL-MSGID: 1785852529905532814 While the GPIO cdev gpio_ioctl() call is in progress, the kernel can call gpiochip_remove() which will set gdev->chip to NULL, after which any subsequent access will cause a crash. gpio_ioctl() was overlooked by the previous fix to protect syscalls (bdbbae241a04), so add protection for that. Fixes: bdbbae241a04 ("gpiolib: protect the GPIO device against being dropped while in use by user-space") Fixes: d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines") Fixes: 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL") Fixes: aad955842d1c ("gpiolib: cdev: support GPIO_V2_GET_LINEINFO_IOCTL and GPIO_V2_GET_LINEINFO_WATCH_IOCTL") Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 744734405912..9155c54acc1e 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -2598,10 +2598,7 @@ static int lineinfo_unwatch(struct gpio_chardev_data *cdev, void __user *ip) return 0; } -/* - * gpio_ioctl() - ioctl handler for the GPIO chardev - */ -static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +static long gpio_ioctl_unlocked(struct file *file, unsigned int cmd, unsigned long arg) { struct gpio_chardev_data *cdev = file->private_data; struct gpio_device *gdev = cdev->gdev; @@ -2638,6 +2635,17 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } } +/* + * gpio_ioctl() - ioctl handler for the GPIO chardev + */ +static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct gpio_chardev_data *cdev = file->private_data; + + return call_ioctl_locked(file, cmd, arg, cdev->gdev, + gpio_ioctl_unlocked); +} + #ifdef CONFIG_COMPAT static long gpio_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) From patchwork Thu Dec 21 01:20:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181936 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp120150dyi; Wed, 20 Dec 2023 17:21:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBOSq6Fg2IZdVxyYnqZcWTVXfTHgWp2XX8jr14wQkMX3FmB3Qvnj0w/9u1lKJi6NWfKH3W X-Received: by 2002:a9d:4d91:0:b0:6db:9eec:f3e1 with SMTP id u17-20020a9d4d91000000b006db9eecf3e1mr3708254otk.28.1703121705909; Wed, 20 Dec 2023 17:21:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703121705; cv=none; d=google.com; s=arc-20160816; b=KZ3putB6WvX2cU2wrQgL1kYiKyt96vPUPeJHGqPyO8Tx9RGbb73/0mgq/LWP2MGaF7 rfCz5vK0wcXHBHvX4Ssa+Pd/qGV+RBBsteGRZDHjDcbtQpWqlIIURtsI0B68MiNpI+Im fqDRvrOdWKGz9H7RS4D7E7n04aGP7TyMPP5kKNsUbiOyN8Nrt8Qlq3vyu1qavSGHnqr1 aW1nJzdhYCd4Y/KB3dCoT2I0W92F0Y3dJHMTIo8QIXJ4wuUsTf+pIWNgu1ztcaAM9Nhg 2Q2JeJFdl8jnI4JM5wpksEkG6u2ftNclLBSsEoY4k1G4FTvWX82wDDnDmdhouqB9IXkU Ur/Q== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=H0+OiIGPu+HUKHHy83yKhozaVuLruzud+CSwPTxOtko=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=WiRmz7HliBT9Z1FEfyjhaWmXxq5aTc38d7Ff98YWYXQHvq1grN6kbbkjlfoJBwQWcZ 5+KBVCrBavuEWvm0AFN8YUsRHC7xfALzn0UoetvPAQoRnAhRflChRVxGAhnCH8PDXzHk JFwwIsAUxd7C9k9LKGTVBEQAl9Pqxak92cPsOSXQARKHBDoyx4zWNNYcN29k3+kHMDYO jIX9Dy7yST1JcBJHj5wzzQeMdKyM6k32suW9PDT+Gkmdb3H58TmwRE8RWuuuYo2Wufqg aLTfwIkrTjSQPqxhYWkFDS8VUSRw+PbAVPZVSx1XdaIaTX7Pefl997KHkDUfHW7jw2XW cquw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hgbhec6t; spf=pass (google.com: domain of linux-kernel+bounces-7720-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7720-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p8-20020a63e648000000b005cd88585706si608481pgj.828.2023.12.20.17.21.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7720-ouuuleilei=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=hgbhec6t; spf=pass (google.com: domain of linux-kernel+bounces-7720-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7720-ouuuleilei=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 EB0C4B2427A for ; Thu, 21 Dec 2023 01:21:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F6343C02; Thu, 21 Dec 2023 01:21:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hgbhec6t" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 3D61B441C; Thu, 21 Dec 2023 01:21:30 +0000 (UTC) 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-pf1-f172.google.com with SMTP id d2e1a72fcca58-6d940d14d69so212279b3a.1; Wed, 20 Dec 2023 17:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703121690; x=1703726490; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H0+OiIGPu+HUKHHy83yKhozaVuLruzud+CSwPTxOtko=; b=hgbhec6tvgvwNiiyP5nKYCA6iNmD6dQGhr9/zh0FhG8eWSliw9VBPzfKxNxi7yBhJr b15+szLGoY7oGoedeG05KwiQEPwetJJMXfbwm2LtZ0esMx1nipPAoDKlXFLOakIhK/Oh OU/WcgmhyXr4IHCKOdCRWrF7kWDcl7c4aQjg7K2CBRcjePORavqbiO6ZBmSJETwfMZqR jX0eBV2gj5ZHYFasrqiMtvVLwYtGgJoT7HVpVmd7qv/jHT5k6YUC4pmnhyMy4IrfClat 5aruZdTW+FYTVS9LCIahbfHm4FOGn5+5YU5y5idSGi7Ukfk/U9cDLtgSTods14WSASlf P5zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703121690; x=1703726490; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H0+OiIGPu+HUKHHy83yKhozaVuLruzud+CSwPTxOtko=; b=X2/UfVVMofnIUY873y92NtgNwxfskjmVBwQn+Bs8IBoO+pcSeLvFgA1RixubaeiChz 0O53iT4bcM8b4NxgB3dp9BHuBskSrIuEMuUHMp5hRzPX58p4TsALBFDuBiuwC1Tlw2VK Vk77+7RBH9T7IvkzUZ26mBYRjwtjzROW10yQRNVvZuUzY6N3Bf9SoG3Fd3EdtFPI8tba LTHcnpM8rOmUY+sZ7yu13PgUEv1iYEjDi8R1+b1EWr7DFV4LToCqdbrwuFkQTbRbJlFi XqDpKdpqlhWDkgfvLUssZ+en54+pnIS3yqhwylOOuG61NInCHrYXIY/v3pj0lgcwcwPC MMSg== X-Gm-Message-State: AOJu0Yz9MRCTxf38P4f1JJonfW/kHFmZhYbY9y/mtB3aB9Remuh7sNs/ uov/qXf+7AtrgyD5v3CMsyaY8H64Qy4= X-Received: by 2002:a62:b40f:0:b0:6d2:6b1f:b82 with SMTP id h15-20020a62b40f000000b006d26b1f0b82mr5942972pfn.67.1703121689794; Wed, 20 Dec 2023 17:21:29 -0800 (PST) Received: from rigel.home.arpa (60-241-235-125.tpgi.com.au. [60.241.235.125]) by smtp.gmail.com with ESMTPSA id x1-20020a056a00270100b006d088356541sm375959pfv.104.2023.12.20.17.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:29 -0800 (PST) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, andy@kernel.org Cc: Kent Gibson Subject: [PATCH v2 2/5] gpiolib: cdev: include overflow.h Date: Thu, 21 Dec 2023 09:20:37 +0800 Message-Id: <20231221012040.17763-3-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231221012040.17763-1-warthog618@gmail.com> References: <20231221012040.17763-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785852545720617458 X-GMAIL-MSGID: 1785852545720617458 struct_size() is used to calculate struct linereq size, so explicitly include overflow.h. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 9155c54acc1e..942fe115b726 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include From patchwork Thu Dec 21 01:20:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp120209dyi; Wed, 20 Dec 2023 17:21:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFzAmKleZPXWze3lCFt6wh7KiKtJU8aC7elB4Iv9tr4heJK965k2urnsLmAiGTA0aDWzQ9i X-Received: by 2002:a2e:9ec4:0:b0:2ca:2d1:9f07 with SMTP id h4-20020a2e9ec4000000b002ca02d19f07mr8983239ljk.5.1703121719263; Wed, 20 Dec 2023 17:21:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703121719; cv=none; d=google.com; s=arc-20160816; b=hTjVhG29wcr/FHf6bW8i/S1tGz/kzRf5hUfnJzl7JDZKzl+GlNP+Dim09fuhAd2fTW b9V6WSGhaEaYfueYzCk51mX2roMZAjylOUH+mUvcKoqxlT13HkFVia2C0KR5R9zKbYhe /xcGoLK1oRB1Rdm+sg6TGrCZr9Vd33cl5epNJrO2VPidiyoqTsj+DDYWr0SumQ7TEa52 Uk7IKvOH6ArUOMN7FRb5z50OhxvV4DsudhwkjxCx+OR0+iAu4Vg0oxBTvMeOYs2E3rQA X7GcGdIYbVDOlq8mCdgwdJ9Yv+0qgq0FZaO+iK+PkdOHrctH5mpZH4fjV1oEYPXYOtCf ZwWA== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2G9xQuVfP3PvQMdAXCehswOfS0hQP216b/ZuRf+VAvA=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=piyOhvHPEQ419I2Ri2f+xJyfeKq/7wS0oTanGg4C3gm36de/LlDvsRJ9+yn9imswzk A7wWO9DvPz/hv4N6OObsw6OB0GCZ+BpKOfW0+rGfsMZxMtDoHy/zdLSG4HxEJORA/VrO 6qxkJEccy3/xHAedm1sjrTPi5vc16D4c1yejFDx20bHJinyTGhb9q2XBFMxaJQxZvHr+ eCuC7sLFHdL0Ieg9B6nNUC30a2s0AgdS08zFmA9RwoG2wH7h51nFNTbB32saoUD8y1fB 3hdQAAqRnKtnLY/nrK+qLQAU0t1YZZkkzUc3U3q2GF/uHixQxxzPShH+q+HrmA7dF3qv kBAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UpQHKdco; spf=pass (google.com: domain of linux-kernel+bounces-7721-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7721-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r12-20020a05640251cc00b00553aa95d2afsi360108edd.635.2023.12.20.17.21.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7721-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UpQHKdco; spf=pass (google.com: domain of linux-kernel+bounces-7721-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7721-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id D9B3C1F24281 for ; Thu, 21 Dec 2023 01:21:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B65392917; Thu, 21 Dec 2023 01:21:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UpQHKdco" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 E5F2F441E; Thu, 21 Dec 2023 01:21:43 +0000 (UTC) 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-pf1-f182.google.com with SMTP id d2e1a72fcca58-6d939e2f594so279749b3a.3; Wed, 20 Dec 2023 17:21:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703121703; x=1703726503; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2G9xQuVfP3PvQMdAXCehswOfS0hQP216b/ZuRf+VAvA=; b=UpQHKdcoXOEWAcWuDy31PP25zJVptPd+LUeGrfIi3iVEd/PE2/YLCprDGR5UIj6Hal l9AFsVLl1mp+WHsHQ1UeSLrhPO8+8JSrNcrs4FMWu82a1Y/9BD2O3xkQmSYru4mDAYug /ighy7zw/2h1CDr4mi3n8XZnTO7GWgmwjgjGEDptlVoHAn0xV+gXDi2Aw9y6IA3bpubX P/E8SCvZKs3HaLmsJch1huEk12CoWRyzAxvkTBmZU+3CxqqwY/JJHnT/66fIo14DykEC LoTxZdc7z8DsjZxXxa1/uYjC+7ljVwPqbPIAxZ/SSpHTIXjn5bBTXp8+MoOXl/sdGeM1 lqJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703121703; x=1703726503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2G9xQuVfP3PvQMdAXCehswOfS0hQP216b/ZuRf+VAvA=; b=jQyy+Hwq/6UK28qHB0JRmE3UvIVH9DjlfO3OPSp2YlWcKybWsOQfZxySQuZRMw0J7x DJ783CNaCjeQcj0pf0RZJSLHEHSR9oLYfE8/OwhuY6gedPLaoL1907JjuMvFG8eotlgE uQwACUe1SUDjCUg4Fn7mqdJBXHDDBhG7N479/AACETnBQ8yJZB1UCzUQs4072I9eiLtR kRrQ/AXiznriZowbQei+V8+9O/UjHQMFuR7rAi5/F/WD2pOpUWyidzl5z61Ot3IS+JRs a824tCtwcj3FjnWCSe2dnp3jIf2TShitgaewqmzPmY3eilPqDMmjdNPkF4W1oyGz/k7y ODZQ== X-Gm-Message-State: AOJu0YzmTTaFnsH2VVylnSzt4Ap4WQdDiVF49cDPpwlKjhbsmFIh9/mh Dy/PqsjdUJvb981RCf4eJlbYBDNEYwE= X-Received: by 2002:a05:6a20:7da4:b0:194:dd52:bdc7 with SMTP id v36-20020a056a207da400b00194dd52bdc7mr856347pzj.56.1703121703104; Wed, 20 Dec 2023 17:21:43 -0800 (PST) Received: from rigel.home.arpa (60-241-235-125.tpgi.com.au. [60.241.235.125]) by smtp.gmail.com with ESMTPSA id x1-20020a056a00270100b006d088356541sm375959pfv.104.2023.12.20.17.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:42 -0800 (PST) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, andy@kernel.org Cc: Kent Gibson Subject: [PATCH v2 3/5] gpiolib: cdev: allocate linereq using kvzalloc() Date: Thu, 21 Dec 2023 09:20:38 +0800 Message-Id: <20231221012040.17763-4-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231221012040.17763-1-warthog618@gmail.com> References: <20231221012040.17763-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785852559594676939 X-GMAIL-MSGID: 1785852559594676939 The size of struct linereq may exceed a page, so allocate space for it using kvzalloc() instead of kzalloc() to handle the case where memory is heavily fragmented and kzalloc() cannot find a sufficient contiguous region. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 942fe115b726..5424c878627e 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1723,7 +1723,7 @@ static void linereq_free(struct linereq *lr) kfifo_free(&lr->events); kfree(lr->label); gpio_device_put(lr->gdev); - kfree(lr); + kvfree(lr); } static int linereq_release(struct inode *inode, struct file *file) @@ -1788,7 +1788,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) if (ret) return ret; - lr = kzalloc(struct_size(lr, lines, ulr.num_lines), GFP_KERNEL); + lr = kvzalloc(struct_size(lr, lines, ulr.num_lines), GFP_KERNEL); if (!lr) return -ENOMEM; lr->num_lines = ulr.num_lines; From patchwork Thu Dec 21 01:20:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp120316dyi; Wed, 20 Dec 2023 17:22:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFaH5PzT4C3z/aQhbTpZqTglfEux6+WHgvVjpgjYWJ0lnuyqloOvGcUpToYIuZf5DzcJbUr X-Received: by 2002:a05:622a:452:b0:423:a9a5:da99 with SMTP id o18-20020a05622a045200b00423a9a5da99mr5338700qtx.13.1703121734151; Wed, 20 Dec 2023 17:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703121734; cv=none; d=google.com; s=arc-20160816; b=g0FDsg2/ifKzffAnfc9spB+CFinNW6rAk5qXJJtzYiAiY4kNMOFwV+HMzI+o8qK5K+ MLCXIhk17ntME0J0rLwCP+CSJ1Y0ewTEByNZU5SbSXjpK4MSAaGXDzbfwsQS6tPlx8YZ mHuqzVwKcK/TYSZI/FeuVrxFTrVSeWwFPOYUntMadvNO8cOszKgrM/EAjGQ2GR4SPONH AYJMJtvhvpug72wC2DvURJUIk3qTz5yZXz9cwZD1zW8fyLf22QGtzG2kKiKHJmPbxn5E ipaAhlg1bXgJOCcZxlBjclBt05aA/Y94MkNGR/e7+FqkFnAGxN/iuKVclC5aTEXMAzcj 2F5g== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=yEnEXmwh1Gejk6pPQlc8WucbY92GrZLw8XwSVMxV33c=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=wMlgyppYFOQVX5vJUNeG4ODccU4KWY5PrXKo3Ma+aprCkiEq+rDgVkGLUKkQ7sT5Jy vrWd7vUh+A1ORB76UmlgA3ZHZMGlFMhyJdrLPefo3YJ7E1rrrKSNSPfSZoEg6JDhL7jQ qo5BZ/fZKhlQph/cdFplhGCwjwUFiBfs9o34LnvhZxfnm71UBDerwY5dzrJDG/EbwJVv YaluBQrm3G7UEgLdtoLCGMCD4KtiByS47Lo2Tzu9s1RitXeOSvKFZ2IcpwjsXmsCaTXW 0DhMyl/rGxfDn1eJdamU3w7Nk8YxRTAg5poaQBehTY4Xt5nwU8qsIboiZB9SVgNFbxiS y8Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N07OHKQE; spf=pass (google.com: domain of linux-kernel+bounces-7722-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7722-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d3-20020ac85ac3000000b00417f76c422fsi999434qtd.380.2023.12.20.17.22.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:22:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7722-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=N07OHKQE; spf=pass (google.com: domain of linux-kernel+bounces-7722-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7722-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id DC9B81C230E2 for ; Thu, 21 Dec 2023 01:22:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DDA5C28FC; Thu, 21 Dec 2023 01:22:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N07OHKQE" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 EDC2D441E; Thu, 21 Dec 2023 01:21:58 +0000 (UTC) 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-pg1-f177.google.com with SMTP id 41be03b00d2f7-5cd86e3a9afso193163a12.1; Wed, 20 Dec 2023 17:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703121718; x=1703726518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yEnEXmwh1Gejk6pPQlc8WucbY92GrZLw8XwSVMxV33c=; b=N07OHKQEe61SbHlssDrW4vxmLV2ZY84Ek83lmNtSQpSMkCkNhm3kGU8Ao0M/+ZkMFz tp85b1kgcnMnoQsntmr97PhhA6Fdgw4qCy6qW5gLkl4MpqF0HsbQtAg+zU6TS9B1D0D8 SH/dFD6ghJklPVMc4UPn/7n5Ra1sZW1MBu8r0U1EY2obysjHGRlIZq2iVyui/kY3DzAA zl2pP2NGEeJbPVv6cAbC+1pxZ7cAAc0I+7Y8gGTSCoKnCWhe2KgJq7rO9S0AfIg10gpI B7pEkYwyFIc6QcjploHcTKf2qv9yAFVOuLFnT7dSy3ehj+wKvduiwAfsCrp/c7HcqEI2 aeBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703121718; x=1703726518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yEnEXmwh1Gejk6pPQlc8WucbY92GrZLw8XwSVMxV33c=; b=NsxbN0FF0V1JH3AQDe1XmbAxWQUexph8rBdgVPV5mCh29nX5Ve/ad0636qn92LuKwa 0bZT1BVrtyeX5zDM2dBayitjzrU2NxJs/8Nw5SEwlnpDUpCiadD+gAFJsx6fRIw95CFD +a/J4ZfKKv6worN24n+Bor5x51TOim/bIkUOGJ9vgEjlYcUgrBNkVkJ+n78pqs3FsUfn qeaViLhEFlYz41JJjsy9+A5Ei/vCRKhBeXS6K4JP6uQe8/jHS5u0Be1dpkEWF8NRBXFc 6jdaq0xMJARmBZ+9nh74tPmuoKYeo/xvMy1FJaNxzeL0H/9NC+UJ1UaINxikMKCY8N6F nqKA== X-Gm-Message-State: AOJu0YwPHdcr40lLmPrgxJq1NhSS5AORhLRZezTNduUlgwlaiFncH1xK OSQwCg4JGYTkqp2WJ1dhrOnzX1M0DQw= X-Received: by 2002:a05:6a21:99a0:b0:195:f2:1fb3 with SMTP id ve32-20020a056a2199a000b0019500f21fb3mr370653pzb.42.1703121717904; Wed, 20 Dec 2023 17:21:57 -0800 (PST) Received: from rigel.home.arpa (60-241-235-125.tpgi.com.au. [60.241.235.125]) by smtp.gmail.com with ESMTPSA id x1-20020a056a00270100b006d088356541sm375959pfv.104.2023.12.20.17.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:21:57 -0800 (PST) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, andy@kernel.org Cc: Kent Gibson Subject: [PATCH v2 4/5] gpiolib: cdev: replace locking wrappers for config_mutex with guards Date: Thu, 21 Dec 2023 09:20:39 +0800 Message-Id: <20231221012040.17763-5-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231221012040.17763-1-warthog618@gmail.com> References: <20231221012040.17763-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785852575296846667 X-GMAIL-MSGID: 1785852575296846667 After the adoption of guard(), the locking wrappers that hold the config_mutex for linereq_set_values() and linereq_set_config() no longer add value, so combine them into the functions they wrap. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 63 ++++++++++++++----------------------- 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 5424c878627e..9ff2b447cc20 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -1454,14 +1454,19 @@ static long linereq_get_values(struct linereq *lr, void __user *ip) return 0; } -static long linereq_set_values_unlocked(struct linereq *lr, - struct gpio_v2_line_values *lv) +static long linereq_set_values(struct linereq *lr, void __user *ip) { DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX); + struct gpio_v2_line_values lv; struct gpio_desc **descs; unsigned int i, didx, num_set; int ret; + if (copy_from_user(&lv, ip, sizeof(lv))) + return -EFAULT; + + guard(mutex)(&lr->config_mutex); + /* * gpiod_set_array_value_complex() requires compacted desc and val * arrays, rather than the sparse ones in lv. @@ -1472,12 +1477,12 @@ static long linereq_set_values_unlocked(struct linereq *lr, bitmap_zero(vals, GPIO_V2_LINES_MAX); /* scan requested lines to determine the subset to be set */ for (num_set = 0, i = 0; i < lr->num_lines; i++) { - if (lv->mask & BIT_ULL(i)) { + if (lv.mask & BIT_ULL(i)) { /* setting inputs is not allowed */ if (!test_bit(FLAG_IS_OUT, &lr->lines[i].desc->flags)) return -EPERM; /* add to compacted values */ - if (lv->bits & BIT_ULL(i)) + if (lv.bits & BIT_ULL(i)) __set_bit(num_set, vals); num_set++; /* capture desc for the num_set == 1 case */ @@ -1493,7 +1498,7 @@ static long linereq_set_values_unlocked(struct linereq *lr, if (!descs) return -ENOMEM; for (didx = 0, i = 0; i < lr->num_lines; i++) { - if (lv->mask & BIT_ULL(i)) { + if (lv.mask & BIT_ULL(i)) { descs[didx] = lr->lines[i].desc; didx++; } @@ -1507,31 +1512,28 @@ static long linereq_set_values_unlocked(struct linereq *lr, return ret; } -static long linereq_set_values(struct linereq *lr, void __user *ip) -{ - struct gpio_v2_line_values lv; - - if (copy_from_user(&lv, ip, sizeof(lv))) - return -EFAULT; - - guard(mutex)(&lr->config_mutex); - - return linereq_set_values_unlocked(lr, &lv); -} - -static long linereq_set_config_unlocked(struct linereq *lr, - struct gpio_v2_line_config *lc) +static long linereq_set_config(struct linereq *lr, void __user *ip) { + struct gpio_v2_line_config lc; struct gpio_desc *desc; struct line *line; unsigned int i; u64 flags, edflags; int ret; + if (copy_from_user(&lc, ip, sizeof(lc))) + return -EFAULT; + + ret = gpio_v2_line_config_validate(&lc, lr->num_lines); + if (ret) + return ret; + + guard(mutex)(&lr->config_mutex); + for (i = 0; i < lr->num_lines; i++) { line = &lr->lines[i]; desc = lr->lines[i].desc; - flags = gpio_v2_line_config_flags(lc, i); + flags = gpio_v2_line_config_flags(&lc, i); gpio_v2_line_config_flags_to_desc_flags(flags, &desc->flags); edflags = flags & GPIO_V2_LINE_EDGE_DETECTOR_FLAGS; /* @@ -1539,7 +1541,7 @@ static long linereq_set_config_unlocked(struct linereq *lr, * or output, else the line will be treated "as is". */ if (flags & GPIO_V2_LINE_FLAG_OUTPUT) { - int val = gpio_v2_line_config_output_value(lc, i); + int val = gpio_v2_line_config_output_value(&lc, i); edge_detector_stop(line); ret = gpiod_direction_output(desc, val); @@ -1550,7 +1552,7 @@ static long linereq_set_config_unlocked(struct linereq *lr, if (ret) return ret; - ret = edge_detector_update(line, lc, i, edflags); + ret = edge_detector_update(line, &lc, i, edflags); if (ret) return ret; } @@ -1562,23 +1564,6 @@ static long linereq_set_config_unlocked(struct linereq *lr, return 0; } -static long linereq_set_config(struct linereq *lr, void __user *ip) -{ - struct gpio_v2_line_config lc; - int ret; - - if (copy_from_user(&lc, ip, sizeof(lc))) - return -EFAULT; - - ret = gpio_v2_line_config_validate(&lc, lr->num_lines); - if (ret) - return ret; - - guard(mutex)(&lr->config_mutex); - - return linereq_set_config_unlocked(lr, &lc); -} - static long linereq_ioctl_unlocked(struct file *file, unsigned int cmd, unsigned long arg) { From patchwork Thu Dec 21 01:20:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp120415dyi; Wed, 20 Dec 2023 17:22:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGIuM6pF2uCYlOYz5Tgi0N5OmhozSPLtMu+tzc0Jux6a/jqK68g6U8HUmfL5yVv7Av2Kks X-Received: by 2002:a05:6e02:198f:b0:35f:d1aa:f41c with SMTP id g15-20020a056e02198f00b0035fd1aaf41cmr825209ilf.10.1703121751365; Wed, 20 Dec 2023 17:22:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703121751; cv=none; d=google.com; s=arc-20160816; b=sR1c04ML8TECHZ0Md/wiAQS6rot+SVzfvErQP/g+p4iWoZadOqsL/slago7MQG5eVT P5rChpIC8PfcvV0Iax7/bVCtegySbStoBgmGEDHC6QLCa0Sr2NTRPbMyWWq5MNZuCMD4 77oDfzm5UNZjYbH/KQjRr7rs6ebQClEd7H10msrCWREUyWn7KmEajyC778P7mQ7xMP5H LOpN5kMah1GZY0J6YcSMgc1r+zTEZStUcij8LeluV5DgZEeb1Dk9H+SyCjloTGK0T04h L0ASia9vs1xSmEquvxPLKFBLaQEcoBJdaKCdnpyi4QjHqmh3XQouyW85ZxmjKpITRI/1 XYZw== ARC-Message-Signature: i=1; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4oIuaHLOj8O8LSsFxzvBYQlFdWLFJBkiRSrLUWFUI2U=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=M68NvvLUcHqbPpX3eUJvFocv18EkT1BB+o8GIilQpKirYdpn6I5IR7zOObNrklzlJ1 7ts+B2FG15wBjcOJVNWruBAs2RS3pl4aQacDd+7HP+e1IwBxI1ZvezlgXw4lHVhR86GP AGl1GcxEGzepiUHlPzGt+s46NjdX/NzUeOgrG6W60YsO/TYv5gognFd2hwvInzqByE3r zFSuL66Q/86uYXwgOBH1tgqPU/YVPa7HggYlYGpB6XUeISPqkC6OHWVhwEspEDdjF6Y4 k44OmGtNiUUC3vEYup3dTg61Xa2aR68JqXBy72zIroaVs8XEmHRctRFiZtBxVuO8n19p I/Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UVdHktCq; spf=pass (google.com: domain of linux-kernel+bounces-7723-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7723-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bn3-20020a056a02030300b005c661efffd0si651561pgb.754.2023.12.20.17.22.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:22:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7723-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UVdHktCq; spf=pass (google.com: domain of linux-kernel+bounces-7723-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7723-ouuuleilei=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 3ED2BB24238 for ; Thu, 21 Dec 2023 01:22:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92F82291D; Thu, 21 Dec 2023 01:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UVdHktCq" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (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 559DF4419; Thu, 21 Dec 2023 01:22:13 +0000 (UTC) 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-ot1-f47.google.com with SMTP id 46e09a7af769-6da69dd6e9fso189255a34.1; Wed, 20 Dec 2023 17:22:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703121732; x=1703726532; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4oIuaHLOj8O8LSsFxzvBYQlFdWLFJBkiRSrLUWFUI2U=; b=UVdHktCq3w70KOorItu17K2Fve6VFbveD+CAUOP4rWxUIH1HjMW7rIAvf5g5Qtt8LN OZolnuC8WjLp4TOXj3v6nWJRNDKXJHJbiSd4/RPadPKTCVHUjFI++oc39SQYK8JKydiO 8iwPJBeH7CMNbgG438InKpWQc4XNX47SMAj7FmV2twmGPhXqvW/heInOW/MnSAaNa9jo SZpiCTOOGZ0RVdlRbsFEbuG6YXZskEoi+rtGlbyR606P63D5NvW+HHm9SXB3lrb373fx 6hdSEmB5Q72jJXv27Z69bSXf9nmqXs7z/LoMQ4XAtmo7nwsJevvgTGn/ar7cmcVQfERW bFAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703121732; x=1703726532; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4oIuaHLOj8O8LSsFxzvBYQlFdWLFJBkiRSrLUWFUI2U=; b=ivf1zgAFhOOp16VNnUHxKuhVg8JTinjQ4IrXWTp/tlUeNdvhTnZFcFve7m+WSQezfg MVNRPwgDk65aw55nqAPshX6yOPLj2A1PfMoDplJFb8GfsCqkpucPPSyncgZE6oxCIk9j sQ+S/NFjGOAeGxyFigcn/spUgj2zRvyckcB8vTvJQ1XFf3rK0YvFI3aocUf+8XDIji36 3+/CSMhjcHaE8Cela1zDTuXGW2afQodx/OxRjswAk+Vaf8ArNYz3cFKMKgNhMH0mWqIc nL+MuDc/lgk/guHTNg613ajkr/uhqzgNeJUUiX67bJMKJU2xl+A3Xi7fYv5hjVHvu6ML lEUg== X-Gm-Message-State: AOJu0Yy1DUtxVWNMmsop8xfteevzuRjWL8iPBdHgN1h/PVAgxiP+UrbE 8nmahs87tWLBXT44/KndQxTELwUC0ZI= X-Received: by 2002:a05:6830:138a:b0:6db:b215:ad8d with SMTP id d10-20020a056830138a00b006dbb215ad8dmr1070230otq.36.1703121732119; Wed, 20 Dec 2023 17:22:12 -0800 (PST) Received: from rigel.home.arpa (60-241-235-125.tpgi.com.au. [60.241.235.125]) by smtp.gmail.com with ESMTPSA id x1-20020a056a00270100b006d088356541sm375959pfv.104.2023.12.20.17.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 17:22:11 -0800 (PST) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, andy@kernel.org Cc: Kent Gibson Subject: [PATCH v2 5/5] gpiolib: cdev: replace locking wrappers for gpio_device with guards Date: Thu, 21 Dec 2023 09:20:40 +0800 Message-Id: <20231221012040.17763-6-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231221012040.17763-1-warthog618@gmail.com> References: <20231221012040.17763-1-warthog618@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785852593221403736 X-GMAIL-MSGID: 1785852593221403736 Replace the wrapping functions that inhibit removal of the gpio chip with equivalent guards. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 205 +++++++++--------------------------- 1 file changed, 47 insertions(+), 158 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 9ff2b447cc20..2a88736629ef 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -65,45 +66,6 @@ typedef long (*ioctl_fn)(struct file *, unsigned int, unsigned long); typedef ssize_t (*read_fn)(struct file *, char __user *, size_t count, loff_t *); -static __poll_t call_poll_locked(struct file *file, - struct poll_table_struct *wait, - struct gpio_device *gdev, poll_fn func) -{ - __poll_t ret; - - down_read(&gdev->sem); - ret = func(file, wait); - up_read(&gdev->sem); - - return ret; -} - -static long call_ioctl_locked(struct file *file, unsigned int cmd, - unsigned long arg, struct gpio_device *gdev, - ioctl_fn func) -{ - long ret; - - down_read(&gdev->sem); - ret = func(file, cmd, arg); - up_read(&gdev->sem); - - return ret; -} - -static ssize_t call_read_locked(struct file *file, char __user *buf, - size_t count, loff_t *f_ps, - struct gpio_device *gdev, read_fn func) -{ - ssize_t ret; - - down_read(&gdev->sem); - ret = func(file, buf, count, f_ps); - up_read(&gdev->sem); - - return ret; -} - /* * GPIO line handle management */ @@ -238,8 +200,8 @@ static long linehandle_set_config(struct linehandle_state *lh, return 0; } -static long linehandle_ioctl_unlocked(struct file *file, unsigned int cmd, - unsigned long arg) +static long linehandle_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) { struct linehandle_state *lh = file->private_data; void __user *ip = (void __user *)arg; @@ -248,6 +210,8 @@ static long linehandle_ioctl_unlocked(struct file *file, unsigned int cmd, unsigned int i; int ret; + guard(rwsem_read)(&lh->gdev->sem); + if (!lh->gdev->chip) return -ENODEV; @@ -297,15 +261,6 @@ static long linehandle_ioctl_unlocked(struct file *file, unsigned int cmd, } } -static long linehandle_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct linehandle_state *lh = file->private_data; - - return call_ioctl_locked(file, cmd, arg, lh->gdev, - linehandle_ioctl_unlocked); -} - #ifdef CONFIG_COMPAT static long linehandle_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -1564,12 +1519,14 @@ static long linereq_set_config(struct linereq *lr, void __user *ip) return 0; } -static long linereq_ioctl_unlocked(struct file *file, unsigned int cmd, - unsigned long arg) +static long linereq_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) { struct linereq *lr = file->private_data; void __user *ip = (void __user *)arg; + guard(rwsem_read)(&lr->gdev->sem); + if (!lr->gdev->chip) return -ENODEV; @@ -1585,15 +1542,6 @@ static long linereq_ioctl_unlocked(struct file *file, unsigned int cmd, } } -static long linereq_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct linereq *lr = file->private_data; - - return call_ioctl_locked(file, cmd, arg, lr->gdev, - linereq_ioctl_unlocked); -} - #ifdef CONFIG_COMPAT static long linereq_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -1602,12 +1550,14 @@ static long linereq_ioctl_compat(struct file *file, unsigned int cmd, } #endif -static __poll_t linereq_poll_unlocked(struct file *file, - struct poll_table_struct *wait) +static __poll_t linereq_poll(struct file *file, + struct poll_table_struct *wait) { struct linereq *lr = file->private_data; __poll_t events = 0; + guard(rwsem_read)(&lr->gdev->sem); + if (!lr->gdev->chip) return EPOLLHUP | EPOLLERR; @@ -1620,22 +1570,16 @@ static __poll_t linereq_poll_unlocked(struct file *file, return events; } -static __poll_t linereq_poll(struct file *file, - struct poll_table_struct *wait) -{ - struct linereq *lr = file->private_data; - - return call_poll_locked(file, wait, lr->gdev, linereq_poll_unlocked); -} - -static ssize_t linereq_read_unlocked(struct file *file, char __user *buf, - size_t count, loff_t *f_ps) +static ssize_t linereq_read(struct file *file, char __user *buf, + size_t count, loff_t *f_ps) { struct linereq *lr = file->private_data; struct gpio_v2_line_event le; ssize_t bytes_read = 0; int ret; + guard(rwsem_read)(&lr->gdev->sem); + if (!lr->gdev->chip) return -ENODEV; @@ -1677,15 +1621,6 @@ static ssize_t linereq_read_unlocked(struct file *file, char __user *buf, return bytes_read; } -static ssize_t linereq_read(struct file *file, char __user *buf, - size_t count, loff_t *f_ps) -{ - struct linereq *lr = file->private_data; - - return call_read_locked(file, buf, count, f_ps, lr->gdev, - linereq_read_unlocked); -} - static void linereq_free(struct linereq *lr) { struct line *line; @@ -1938,12 +1873,14 @@ struct lineevent_state { (GPIOEVENT_REQUEST_RISING_EDGE | \ GPIOEVENT_REQUEST_FALLING_EDGE) -static __poll_t lineevent_poll_unlocked(struct file *file, - struct poll_table_struct *wait) +static __poll_t lineevent_poll(struct file *file, + struct poll_table_struct *wait) { struct lineevent_state *le = file->private_data; __poll_t events = 0; + guard(rwsem_read)(&le->gdev->sem); + if (!le->gdev->chip) return EPOLLHUP | EPOLLERR; @@ -1955,14 +1892,6 @@ static __poll_t lineevent_poll_unlocked(struct file *file, return events; } -static __poll_t lineevent_poll(struct file *file, - struct poll_table_struct *wait) -{ - struct lineevent_state *le = file->private_data; - - return call_poll_locked(file, wait, le->gdev, lineevent_poll_unlocked); -} - static int lineevent_unregistered_notify(struct notifier_block *nb, unsigned long action, void *data) { @@ -1979,8 +1908,8 @@ struct compat_gpioeevent_data { u32 id; }; -static ssize_t lineevent_read_unlocked(struct file *file, char __user *buf, - size_t count, loff_t *f_ps) +static ssize_t lineevent_read(struct file *file, char __user *buf, + size_t count, loff_t *f_ps) { struct lineevent_state *le = file->private_data; struct gpioevent_data ge; @@ -1988,6 +1917,8 @@ static ssize_t lineevent_read_unlocked(struct file *file, char __user *buf, ssize_t ge_size; int ret; + guard(rwsem_read)(&le->gdev->sem); + if (!le->gdev->chip) return -ENODEV; @@ -2042,15 +1973,6 @@ static ssize_t lineevent_read_unlocked(struct file *file, char __user *buf, return bytes_read; } -static ssize_t lineevent_read(struct file *file, char __user *buf, - size_t count, loff_t *f_ps) -{ - struct lineevent_state *le = file->private_data; - - return call_read_locked(file, buf, count, f_ps, le->gdev, - lineevent_read_unlocked); -} - static void lineevent_free(struct lineevent_state *le) { if (le->device_unregistered_nb.notifier_call) @@ -2071,13 +1993,15 @@ static int lineevent_release(struct inode *inode, struct file *file) return 0; } -static long lineevent_ioctl_unlocked(struct file *file, unsigned int cmd, - unsigned long arg) +static long lineevent_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) { struct lineevent_state *le = file->private_data; void __user *ip = (void __user *)arg; struct gpiohandle_data ghd; + guard(rwsem_read)(&le->gdev->sem); + if (!le->gdev->chip) return -ENODEV; @@ -2103,15 +2027,6 @@ static long lineevent_ioctl_unlocked(struct file *file, unsigned int cmd, return -EINVAL; } -static long lineevent_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct lineevent_state *le = file->private_data; - - return call_ioctl_locked(file, cmd, arg, le->gdev, - lineevent_ioctl_unlocked); -} - #ifdef CONFIG_COMPAT static long lineevent_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -2584,12 +2499,17 @@ static int lineinfo_unwatch(struct gpio_chardev_data *cdev, void __user *ip) return 0; } -static long gpio_ioctl_unlocked(struct file *file, unsigned int cmd, unsigned long arg) +/* + * gpio_ioctl() - ioctl handler for the GPIO chardev + */ +static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct gpio_chardev_data *cdev = file->private_data; struct gpio_device *gdev = cdev->gdev; void __user *ip = (void __user *)arg; + guard(rwsem_read)(&gdev->sem); + /* We fail any subsequent ioctl():s when the chip is gone */ if (!gdev->chip) return -ENODEV; @@ -2621,17 +2541,6 @@ static long gpio_ioctl_unlocked(struct file *file, unsigned int cmd, unsigned lo } } -/* - * gpio_ioctl() - ioctl handler for the GPIO chardev - */ -static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - struct gpio_chardev_data *cdev = file->private_data; - - return call_ioctl_locked(file, cmd, arg, cdev->gdev, - gpio_ioctl_unlocked); -} - #ifdef CONFIG_COMPAT static long gpio_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) @@ -2679,12 +2588,14 @@ static int gpio_device_unregistered_notify(struct notifier_block *nb, return NOTIFY_OK; } -static __poll_t lineinfo_watch_poll_unlocked(struct file *file, - struct poll_table_struct *pollt) +static __poll_t lineinfo_watch_poll(struct file *file, + struct poll_table_struct *pollt) { struct gpio_chardev_data *cdev = file->private_data; __poll_t events = 0; + guard(rwsem_read)(&cdev->gdev->sem); + if (!cdev->gdev->chip) return EPOLLHUP | EPOLLERR; @@ -2697,17 +2608,8 @@ static __poll_t lineinfo_watch_poll_unlocked(struct file *file, return events; } -static __poll_t lineinfo_watch_poll(struct file *file, - struct poll_table_struct *pollt) -{ - struct gpio_chardev_data *cdev = file->private_data; - - return call_poll_locked(file, pollt, cdev->gdev, - lineinfo_watch_poll_unlocked); -} - -static ssize_t lineinfo_watch_read_unlocked(struct file *file, char __user *buf, - size_t count, loff_t *off) +static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, + size_t count, loff_t *off) { struct gpio_chardev_data *cdev = file->private_data; struct gpio_v2_line_info_changed event; @@ -2715,6 +2617,8 @@ static ssize_t lineinfo_watch_read_unlocked(struct file *file, char __user *buf, int ret; size_t event_size; + guard(rwsem_read)(&cdev->gdev->sem); + if (!cdev->gdev->chip) return -ENODEV; @@ -2777,15 +2681,6 @@ static ssize_t lineinfo_watch_read_unlocked(struct file *file, char __user *buf, return bytes_read; } -static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, - size_t count, loff_t *off) -{ - struct gpio_chardev_data *cdev = file->private_data; - - return call_read_locked(file, buf, count, off, cdev->gdev, - lineinfo_watch_read_unlocked); -} - /** * gpio_chrdev_open() - open the chardev for ioctl operations * @inode: inode for this chardev @@ -2799,17 +2694,15 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) struct gpio_chardev_data *cdev; int ret = -ENOMEM; - down_read(&gdev->sem); + guard(rwsem_read)(&gdev->sem); /* Fail on open if the backing gpiochip is gone */ - if (!gdev->chip) { - ret = -ENODEV; - goto out_unlock; - } + if (!gdev->chip) + return -ENODEV; cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); if (!cdev) - goto out_unlock; + return -ENODEV; cdev->watched_lines = bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL); if (!cdev->watched_lines) @@ -2838,8 +2731,6 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) if (ret) goto out_unregister_device_notifier; - up_read(&gdev->sem); - return ret; out_unregister_device_notifier: @@ -2853,8 +2744,6 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) bitmap_free(cdev->watched_lines); out_free_cdev: kfree(cdev); -out_unlock: - up_read(&gdev->sem); return ret; }