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) {