From patchwork Wed Dec 20 01:51:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2359198dyi; Tue, 19 Dec 2023 17:51:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IE8qj/xRhM/TU/4hLbx7/gbDrW40QCuDAn/78I53OljmxuwnW89rH2MzYPOTXwctS0phnCC X-Received: by 2002:a05:6808:f91:b0:3b8:7f1b:df8d with SMTP id o17-20020a0568080f9100b003b87f1bdf8dmr22389510oiw.35.1703037116545; Tue, 19 Dec 2023 17:51:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703037116; cv=none; d=google.com; s=arc-20160816; b=cHdZTN9vPkNMdfh1iOzVg4UXeIzUptw57YxBQvY8VaOfPwCQ4My11VpLdosjN2vTJs ecah0CxHS568qm/rAc1bte+1yBQgkh4dxUPJg48jALJzKi/f/hdas6d5eobycNDa/2E1 CnWCfwP1drPLeuW6rviA9hXwv+yET/glc0tcrcE2pzcC6Lw3fVLBRwXSjnCHUEve/4Fn AXJT2p/VsP7yVygGzRoiGAJkofbc54EGHhm8OOfRfPnoa7frfjxb0rVIs6RJZvoJRBo4 Wkhzu9Gm5mF5G2nw5MGT6qlrbrHI3Ako+G95pJ8nPJrhPEesbl964tq8KsXtTVyitnCQ keRQ== 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=fIe64+aq/lZJDDELMuKdnpexZanQFZNO/4y/47rTO3o=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=JqTOdcV4f0mKPBEhSdr/lv0etnpk7ZOQREyujb7B3qnOJvPKwk1ueUf1rknT/Ga2Q+ lzylGq0AEL/hBGl2udMxzBNd9fwBmSuIEbz+QMeWX1WHb9FtdN38w/n9iVGo4B4+hh6k bVLyZfcT1uo+MbMzBgPnXo8kf/0TyB9uoS4K52HFahaTl/WNTwuMDZImZBTQETMfAIVm jk6Ty8GTmXxP7S/OGkb+Q/AHBSc1Xm4GfIwaAuG8GJ/HohO/5Fwv+Ur4FwoFi/J7HkXs E9axMqDaL1lLrpipgWrQREIv87AuzcyZxvZOo8wGC1tMeyLGUrylCuBBAdVtQPOj6i3X 3jZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=M87ghTIO; spf=pass (google.com: domain of linux-kernel+bounces-6267-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6267-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 r2-20020a62e402000000b006d92fd3b0bfsi2370685pfh.78.2023.12.19.17.51.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:51:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6267-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=M87ghTIO; spf=pass (google.com: domain of linux-kernel+bounces-6267-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6267-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 90FC1B247F1 for ; Wed, 20 Dec 2023 01:51:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43CFB8F71; Wed, 20 Dec 2023 01:51:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M87ghTIO" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) (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 4D22D8C00; Wed, 20 Dec 2023 01:51:32 +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-oa1-f44.google.com with SMTP id 586e51a60fabf-1f03d9ad89fso3511765fac.1; Tue, 19 Dec 2023 17:51:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703037091; x=1703641891; 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=fIe64+aq/lZJDDELMuKdnpexZanQFZNO/4y/47rTO3o=; b=M87ghTIOnr0tO0BlINWetR2NqCcePFxLo02NurXxXED5SwJj0CS0HNNQZi891faa+/ 7U9VfIVbLwKF5AsbD7hC2zvhH6JJSQjv7oHvUlDmi+qkhWGUz4yg59a452L2T3Oi2Pjf C7KCL0RPK4AK5aR45TXH2sGwXdCndAg/yeHkwj2JX36a9dCsWMxXsLIpcLdeyHP29n9B LoO5AtWKicb3TVBK52HrQUlbsrlAuaZpAz8IzP9bPTu7Vbs0LEb898YFQfllQ+SRW3R5 ikXpMvdSoHERFyyNJwEiLh6gA26ZB+1caVnSAVPo4+Me6pd1SdA7fxr2TJebGZPBPHmf r5/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703037091; x=1703641891; 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=fIe64+aq/lZJDDELMuKdnpexZanQFZNO/4y/47rTO3o=; b=WybO+f22SmwUDFhC4U+0rIxVzZxE4TgLR1VMh3qX6x+yeA3aJDU1KOmzsRkmZg+yqn kHujiOqIG/M/b8ysWo0pfLASZNUy+AvUx9O7szynT87Ij9cbUYnUPcu1FzF1DjweaFm7 7NTDT3k8JQCF6JI4O+dOde5EtU67KwnE/UoEevcmHqrRmh/S8dtV+JHuTl/aQPUr1kG6 Um8qO2yI8DWXBuSLHE7esGPSkeZBHVb8/Ed9c0Yf2F0+TZfRLdb0JTHGAhI1TqavomR7 yR2riVsyI2GhyrULUDrqfxT67n+jnNg5CwY0bk+YiJ/FDGLJpswEV7cR4g364A3lX5Ql 2lgA== X-Gm-Message-State: AOJu0YyZnhYKRFycIFaf0D+r1abx2Zy0AYMIGGz34o/i1z1n4MQ3dHLQ ug2lvW7JtGgXnWo8sWnwmn7S3rBtNzQ= X-Received: by 2002:a05:6870:b004:b0:1fb:75a:6d2d with SMTP id y4-20020a056870b00400b001fb075a6d2dmr22449061oae.84.1703037091372; Tue, 19 Dec 2023 17:51:31 -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 c17-20020a631c51000000b005b92e60cf57sm20133208pgm.56.2023.12.19.17.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:51:31 -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 1/4] gpiolib: cdev: include overflow.h Date: Wed, 20 Dec 2023 09:51:03 +0800 Message-Id: <20231220015106.16732-2-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231220015106.16732-1-warthog618@gmail.com> References: <20231220015106.16732-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: 1785763847909478290 X-GMAIL-MSGID: 1785763847909478290 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 744734405912..44d864f63130 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 Wed Dec 20 01:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2359271dyi; Tue, 19 Dec 2023 17:52:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWd8UVm1rw+w+XQ+QIN0/1DfrVTd85/QrlFjIqkCuMRSs7t3rd1NHf6Ux6j6rsLeCG+meK X-Received: by 2002:a05:6214:1bcb:b0:67f:2e44:1edd with SMTP id m11-20020a0562141bcb00b0067f2e441eddmr10212775qvc.107.1703037130184; Tue, 19 Dec 2023 17:52:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703037130; cv=none; d=google.com; s=arc-20160816; b=QV44xt0sowBc4gAj54Q03cwEZbw60hJ2Mj8N47bbbhzp6krYuF5Yd81K+cvW0A1FZq /C56mW+OsWzv9ZT7qPxPNo3IYyW3dATtVWEtjmlfEQqpttSy6eryM+wFrleOGyuuUHc+ AQr8DvKI+2yFy3vhkozCs3FGhztCeHe4Qg0bfzlpKOJA8iBKCRYHuITlCl+M7okuMbIx GPn8EU892FIaH6kh7kv4Gw5aE4aZc4SGZmSepdUfVJYUMSmXxrIcwDwdhQM5KChTpmbT QG4RpkDufChnwF+MnFdpoQQLSVat8jEOeAKzITCV4Sm7aPMyDIaaHr2wDUqTj5fyVtRt PjXg== 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=WI6OSf/Ga+zJKuJpAMMrUdNLhytpjOkBSW3YDAz3VbA=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=BvaG4kRzqTy9axbKRj2yberUbv/LA/0STWWlv3qA10/dJb7zvVu31Ljm73aUW+VUV+ O0l/uMBwRBbiGCHOPf00lOo/SypnUHmsg8npU6qZ0NLjH/jdnYAVMoSvJmxWSRoTEBE/ td2w8ATVnsIc1EgnTLmsJVkKw8ECKXhDA9vneic0mAebbRD8OX+rA0pUZ27OJ6TOsdJS EDdYpCm3mjNG4H/jnpmP9FzOaQfnJdyas1GHCxQ1iSiqP/ePJ8dp462GYdJgR3BcR62z ruZY4TTcBoPvXOkHOhXsXqQ6fL9a940EC7JVrFxTVCcdWgA8JRwnDfwZYQKru1HGBbO8 aMFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JoG0HsmL; spf=pass (google.com: domain of linux-kernel+bounces-6268-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6268-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 n1-20020a0c9d41000000b0067f4507b64bsi5433968qvf.408.2023.12.19.17.52.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:52:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6268-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=JoG0HsmL; spf=pass (google.com: domain of linux-kernel+bounces-6268-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6268-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 F025D1C2563A for ; Wed, 20 Dec 2023 01:52:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A623C2D8; Wed, 20 Dec 2023 01:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JoG0HsmL" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (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 96705C2D0; Wed, 20 Dec 2023 01:51: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-oa1-f51.google.com with SMTP id 586e51a60fabf-20389f2780fso3219782fac.2; Tue, 19 Dec 2023 17:51:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703037102; x=1703641902; 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=WI6OSf/Ga+zJKuJpAMMrUdNLhytpjOkBSW3YDAz3VbA=; b=JoG0HsmLRLBsDcJuSnTrOi3ZqCnqS8MYHstj4qydO80Lb9nPA22wFkW6Wl8S567vum JfC19jCDZej43AostQeAM/ibJ4BPjOruQPCPDbi4Q2uVNFvTJro4XUyh1lgNw+8U1TRS k0DtHdaVRZTZul/0V/NTkglcks3MG7QxrsbOIu0cRCIVTX/4yqHw1mhpdExQko/46qSr E+9A+qQRMj/EdzbzSxP+cLJVAqFGAhZjO44RHpN4oK9INpSENg8pfRd/vBTcaxwl3B5J qzlOeCoT+OppSGljC450QL80RoiOkgHjn0fLPuogVL+iMhSEicsvJKh0NMNDs46r/d28 XPPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703037102; x=1703641902; 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=WI6OSf/Ga+zJKuJpAMMrUdNLhytpjOkBSW3YDAz3VbA=; b=lyHyBdCFsisT73rIzMtnA2L7mR9+u9WBPBfNb1pLc69aIO5xe0qqoQVNF17cJ3qw+t 5tQq3nBxWKBB0T2wkH1KESd4Il06RPaHNp+MeEMxAQidtP5+s3yKnmbxq3GxEosObJE6 no1AnEVR63nv1NegJv9oewvWka1uMPEOtIYn2fB86/Tdc2WDiGpX4/gv6AHyId6FJoJT dNV8Vfdo7+L6m4q3De46MmhSG8k9lMJL1WIl+du5w3HXzwQdtLzZ+XQQTcPxvtPpCDsk 2S+fjSyck4U5awS8mu5ghQM5e+N8+2c6LuoIHB5dyqDIFi6Ac1ty02bbjrebaKRIGv13 27Ww== X-Gm-Message-State: AOJu0YzWU4QI9hyON6hWWSUFwMkdL+/G7cl+IJNuJwt43bowh921BWTr osQj/0GndshKogZ1uF5YpnMsWWCf7cw= X-Received: by 2002:a05:6871:452:b0:204:316:5eeb with SMTP id e18-20020a056871045200b0020403165eebmr1094714oag.62.1703037102543; Tue, 19 Dec 2023 17:51:42 -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 c17-20020a631c51000000b005b92e60cf57sm20133208pgm.56.2023.12.19.17.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:51:41 -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 2/4] gpiolib: cdev: allocate linereq using kvzalloc() Date: Wed, 20 Dec 2023 09:51:04 +0800 Message-Id: <20231220015106.16732-3-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231220015106.16732-1-warthog618@gmail.com> References: <20231220015106.16732-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: 1785763861824833915 X-GMAIL-MSGID: 1785763861824833915 The size of struct linereq may exceed a page, so allocate space for it using kvzalloc() instead of kzalloc(). 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 44d864f63130..6fec793f5513 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 Wed Dec 20 01:51:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2359380dyi; Tue, 19 Dec 2023 17:52:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHnDL52NYsqVTCdIvMulzvu5YfJYewr3ZvJzoiAdImakrSaDlHI/T+f0OdSQYnvXM7Gry1g X-Received: by 2002:a17:906:8882:b0:a23:6051:d335 with SMTP id ak2-20020a170906888200b00a236051d335mr2122187ejc.71.1703037148518; Tue, 19 Dec 2023 17:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703037148; cv=none; d=google.com; s=arc-20160816; b=upIUCJReqmqoQhoQ2d+h1Z15v+9EZe5PC5quW6WUDiSes4+hR1tnskLONXnR5iXe+w d1+7mTf6USkeuynk5zFWXyrIoRtIOP7e+PLqaYN+oD5dyoOdIhbzeo9mkht85NzT2Eti 1QZ+PWeTj+V6fmbyGkPKiKXIEr33I1vj57Ly/MnwflxS/CvMeneikmlt8CeNI1jUEyAP 5yT77E9biA5tuGFbSelN6fc+xkl9rD/R4Qi+ul6zkI7Qq2uXQQ6k7/Ws/THInOYlVcj8 f2BlS2nmba9xiCVsH5RNduO/zU6EaEwIgDLDSfeJX0xf//xVUU6UCgctUD2EqTDCZBVW bLhA== 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=nwJrFBOYeQiMptBpaCTPsCwKHHrwP/LYHeLVCN1wLbM=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=eEnsFeao4Sb9VWTFD0vcDTt0ljSjYa+jBKI4QDtrW/gPv27Mp8apjxUOiKDbUAUYXB h7jzSH7/GZpVVN37QfkywYxj2yI/7z35/cL3T+z3DdjUQhXvMlu56dA4G2MJl4AjcCN9 dux6T1xHr1WkyjNu5T5E9qC3AYfDNoSaD4Qd9NgTrFJp3F5c9C0Sz/fwq7ZZwAevBzY9 tQgPCbFWvSiJKy0xCBfIm1xU3bsLUM/MBW6xLf2JK7hr0X7dLEL3MZe6ZhAAKp3P4qQH S8wQ3tmwy+UKREAS9qu+5qMLMt3vvMMeVDoYkbrwjZ6lx/YiADA7wpTGBU2n/cqkQYZ0 quAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DPeofTou; spf=pass (google.com: domain of linux-kernel+bounces-6269-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6269-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lo17-20020a170906fa1100b00a232c96c0c1si3348398ejb.275.2023.12.19.17.52.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:52:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6269-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DPeofTou; spf=pass (google.com: domain of linux-kernel+bounces-6269-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6269-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 F15EF1F262C9 for ; Wed, 20 Dec 2023 01:52:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E6C08BE5E; Wed, 20 Dec 2023 01:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DPeofTou" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 9AF7911C90; Wed, 20 Dec 2023 01:51:56 +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-f48.google.com with SMTP id 46e09a7af769-6db8ae7a0aeso2293634a34.1; Tue, 19 Dec 2023 17:51:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703037115; x=1703641915; 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=nwJrFBOYeQiMptBpaCTPsCwKHHrwP/LYHeLVCN1wLbM=; b=DPeofTouxy0yaKZd3CIK5CGPUjxkqmpwlOfF1FDAlOCUXOqdrGh1PP1L6L1vwMt/8m YHqDi+HJE7G1JdaJzPS+3NofYBzFFAIVAwp1dp29CvPXJnCnKCrxeCjCn00KI5BfgeNp emPTy246D131AaqFBSowF3/Y50MJqY3RzPZgyviNOm4otZguNOJ1WhbyZaki6ULEAPha MAoJuw0rdzgc6N/CRK5p+v9l9dz0eGbHKpISyJZAw6OoiBhzsPvpmvZUlF2GjH2ze90K nWMEXfBcKT0ljn+SX8UsBcEIdkhLbKosuaizp8ByRgKG8EugYwygLHeo5zj1i98FIuYv MqWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703037115; x=1703641915; 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=nwJrFBOYeQiMptBpaCTPsCwKHHrwP/LYHeLVCN1wLbM=; b=RbZebJ0mA5BO2zixE3TKGxCGDeENaSnjNTTidNDMTcBxH1lWlijQlgIGQrC+pzfurt rQE+I+Y4I25u2thACRv8M99kP+vLkNQNDLEGtomQ7dTMlcbzb8PSiIRAHt59PiZfT2zG VPyQAPHpcjbzvdbbR4F05lh9FCioi2UMKMRpKJ6WhdZxJP65pWau+NPXIzji8xZV14dz P4575ajJMUNeexJnQ4s15agpf48sRpiqvWUIEspfn0hfAjqMu77JVLydsDFNrzAcmClp 6wZznJwR5Ks6RqLVlTA2rHPfze/k8PT2izYKkYn7nFdvVEzJCFX4Y4dss5Qqk75tvZhC sOww== X-Gm-Message-State: AOJu0YwVNwWvqJ3xRk2FZVuVYX94EjVM2ooSUHeedOBZgmGrupE/iui1 VNvmyoHK5BStJRogjeVbR5//N76EVsg= X-Received: by 2002:a05:6808:1984:b0:3bb:6984:f445 with SMTP id bj4-20020a056808198400b003bb6984f445mr1486236oib.34.1703037115430; Tue, 19 Dec 2023 17:51:55 -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 c17-20020a631c51000000b005b92e60cf57sm20133208pgm.56.2023.12.19.17.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:51:55 -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 3/4] gpiolib: cdev: replace locking wrappers for config_mutex with guards Date: Wed, 20 Dec 2023 09:51:05 +0800 Message-Id: <20231220015106.16732-4-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231220015106.16732-1-warthog618@gmail.com> References: <20231220015106.16732-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: 1785763880769237870 X-GMAIL-MSGID: 1785763880769237870 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 6fec793f5513..5b07578e3bfa 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 Wed Dec 20 01:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 181418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2359497dyi; Tue, 19 Dec 2023 17:52:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHuY6csQ2HQkzulPMLVh38EzlzN51Q84FYGqyE1d2DoWJoGJL+xs/lwIC0Jpp6reEaVsFQ2 X-Received: by 2002:a17:906:c302:b0:a19:a1ba:8cdc with SMTP id s2-20020a170906c30200b00a19a1ba8cdcmr7964427ejz.122.1703037165991; Tue, 19 Dec 2023 17:52:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703037165; cv=none; d=google.com; s=arc-20160816; b=A+g2wt1S548OjUvIxxnG6DPCCdcXPLs6yTuKcsf+/yWXqNe52qJd2lb5kX5BDqwwC0 46TRSy4cofW1q3xjgdNv0XluGTHQHoOwTV5W3XYT4TMHYU5FfKnj8sQYRjm6leHd5IHJ gJBeG0G86Z8fi4+JzNbHIlEJM6UVQ2RIQtj7EXoK7qeSM5dWa+qsp/LOfDGZ55b0VjCA pWB97NCEtKHUkTHfFBBPsdaeL+PtipKLlUiBL0Qe2rp9pU8zlMplsB5Tb3oWYX77gz4D 3ulHfyAR4KlOCA8HUHhtYCJM23gA8yWCn+WKUAe1Jik2K1eRmjVu60fwXq4xwfT9bc+K h1cw== 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=4Y9g7c+vuEkFBYBNDHkeNbZIyU4v51PaB2WVpgjrMac=; fh=GNOA1jdeAuH+tfAEzFx15vIukVGFZnqrW9xHApUHjl0=; b=Q03TPvQwooElHhy7nhDjfFJyBokl7Ym7zyil+3VgpDUawRAuk7DVEYZRjDSHPXCHTN fpuqpyZmkIG2RgwHDWSoosUg86DRjCck+AXsYaOZHdKvz7TR7jO/IMPxpmB44YlVG7kn ijI1aYrx6Ntwr+eJ8UcSJZcXmZu2W6lskCEESPmCoai/jSirC8KF7FT8+57ZofzL8DGV oGCjSw78ngattU1sxQjEGGGtJ3+yjpJfDNXjwVgVplF5NaaTxvEO/noCncos6c9XMlOM xfbjyNp+BbskMyiOKlUfyZ6hJbbpL3pSbAY6cZfxxKNLcJ0qVjTvXW6e0irXr3HoSvW7 Nq0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kHOx7Wc4; spf=pass (google.com: domain of linux-kernel+bounces-6270-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6270-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id xa12-20020a170907b9cc00b00a089f01d380si11415612ejc.559.2023.12.19.17.52.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:52:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6270-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=kHOx7Wc4; spf=pass (google.com: domain of linux-kernel+bounces-6270-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6270-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 6EAA71F26949 for ; Wed, 20 Dec 2023 01:52:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35F02D303; Wed, 20 Dec 2023 01:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kHOx7Wc4" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (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 E3F4A1401F; Wed, 20 Dec 2023 01:52:11 +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-il1-f179.google.com with SMTP id e9e14a558f8ab-35f519f3ea9so23483325ab.3; Tue, 19 Dec 2023 17:52:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703037131; x=1703641931; 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=4Y9g7c+vuEkFBYBNDHkeNbZIyU4v51PaB2WVpgjrMac=; b=kHOx7Wc4j0VJnI/QyJ8DLOySMk6QJSzTB/TWw4AW0f5Ld/r7YXjpYk2vpptXjofGFD m6jQzt5sOiLJpX7eULgn96ozNL6OaLG5+fwwU+f5O4c4/OHzv++h4YMHw6oDskXpVkMa /bidtSG5I6sjHQKTdFEMhFwBbc+YDgkUBOZVn0OcEboLcN2lCIBUbKwuSTjC6iuVaNt/ n8jG+Kn3E2+TNNtmuP6CejX6md+7hWb/kBLWZQx0ZPL855iaBstjE8VSUwE7MviT2eJA cIl6FZdPD/nomD3eAdNtApJcrrCnd1IfdUA0WqmHLyX5wlIoWLNHu8Q7JmSOXBx0iZR3 H/TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703037131; x=1703641931; 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=4Y9g7c+vuEkFBYBNDHkeNbZIyU4v51PaB2WVpgjrMac=; b=iMFusXCjdv/q8g70uIAdcQj2+ZZegUHKi5o/ycMDVtfveAFoIgZIcKyGFvSxn0b6kn rbCYh4GGSUbfEcQh7q/RaNmpvX9XjDBZgktMvjT6yOxoIX9qoZSbyvB6hKbr/geSSzoR BCD+GodN9D0y3zhzKJhbHc20oxRRmyVKDSEdShwRmjNbGF4mr4soSXLly1z1xzc8i3wi MTBgl7GdVCOVSrrmM2U7Iem+K8aRTzw6XzEvZX6W41t+MbDu04rGK2hK2d0Sf9w5YBhW bvhH2b3EynSZ9+Jr3EOySNVxq2C3Wfq19svU/rs0D+XhJZ/PaXYkeMqqGDYy2oSy0vUb qK/g== X-Gm-Message-State: AOJu0YxCs7Wp+k9keOpJ8vRohpUUs3Y9iBXJKaYUZD90RP//vAXfcywk zPSYzpA0DIVzytwH9WT73ZfwU7dFZHA= X-Received: by 2002:a92:ca4a:0:b0:35c:e547:d759 with SMTP id q10-20020a92ca4a000000b0035ce547d759mr20146233ilo.12.1703037130920; Tue, 19 Dec 2023 17:52:10 -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 c17-20020a631c51000000b005b92e60cf57sm20133208pgm.56.2023.12.19.17.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 17:52:10 -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 4/4] gpiolib: cdev: replace locking wrappers for gpio_device with guards Date: Wed, 20 Dec 2023 09:51:06 +0800 Message-Id: <20231220015106.16732-5-warthog618@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231220015106.16732-1-warthog618@gmail.com> References: <20231220015106.16732-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: 1785763899203516637 X-GMAIL-MSGID: 1785763899203516637 Replace the wrapping functions that inhibit removal of the gpio_device with equivalent guard macros. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 195 ++++++++++-------------------------- 1 file changed, 52 insertions(+), 143 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 5b07578e3bfa..77ecf308ef39 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -65,44 +65,20 @@ 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; +DEFINE_CLASS(_read_sem_guard, + struct rw_semaphore *, + up_read(_T), + ({ + down_read(sem); + sem; + }), + struct rw_semaphore *sem); - down_read(&gdev->sem); - ret = func(file, cmd, arg); - up_read(&gdev->sem); +/* guard that downs a rw_semaphore while in scope */ +#define read_sem_guard(sem) CLASS(_read_sem_guard, _sem)(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; -} +/* guard on the gpio_device sem to inhibit device removal while in use */ +#define gdev_guard(gdev) read_sem_guard(gdev->sem) /* * GPIO line handle management @@ -238,8 +214,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 +224,8 @@ static long linehandle_ioctl_unlocked(struct file *file, unsigned int cmd, unsigned int i; int ret; + gdev_guard(&lh->gdev); + if (!lh->gdev->chip) return -ENODEV; @@ -297,15 +275,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 +1533,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; + gdev_guard(&lr->gdev); + if (!lr->gdev->chip) return -ENODEV; @@ -1585,15 +1556,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 +1564,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; + gdev_guard(&lr->gdev); + if (!lr->gdev->chip) return EPOLLHUP | EPOLLERR; @@ -1620,22 +1584,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; + gdev_guard(&lr->gdev); + if (!lr->gdev->chip) return -ENODEV; @@ -1677,15 +1635,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 +1887,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; + gdev_guard(&le->gdev); + if (!le->gdev->chip) return EPOLLHUP | EPOLLERR; @@ -1955,14 +1906,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 +1922,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 +1931,8 @@ static ssize_t lineevent_read_unlocked(struct file *file, char __user *buf, ssize_t ge_size; int ret; + gdev_guard(&le->gdev); + if (!le->gdev->chip) return -ENODEV; @@ -2042,15 +1987,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 +2007,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; + gdev_guard(&le->gdev); + if (!le->gdev->chip) return -ENODEV; @@ -2103,15 +2041,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) @@ -2671,12 +2600,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; + gdev_guard(&cdev->gdev); + if (!cdev->gdev->chip) return EPOLLHUP | EPOLLERR; @@ -2689,17 +2620,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; @@ -2707,6 +2629,8 @@ static ssize_t lineinfo_watch_read_unlocked(struct file *file, char __user *buf, int ret; size_t event_size; + gdev_guard(&cdev->gdev); + if (!cdev->gdev->chip) return -ENODEV; @@ -2769,15 +2693,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 @@ -2791,17 +2706,15 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) struct gpio_chardev_data *cdev; int ret = -ENOMEM; - down_read(&gdev->sem); + gdev_guard(&gdev); /* 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) @@ -2830,8 +2743,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: @@ -2845,8 +2756,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; }