From patchwork Thu Nov 7 07:15:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 842563 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.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 7E72812B63; Thu, 7 Nov 2024 07:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963751; cv=none; b=BUCaRpXKRYogmqP+VuGmH4MRp4aJ18QYHQvI4RMPrRmNNRfHQoBYSwTXOcS1Rod/I9Krq1ynr/vD3qIOHoVn3E+syr7qer7RJEGcSK8CPhlVdwUOYGG6uLOYRy5w+F7PXOW63q1pKjFFsSd0GvNnjjGmhUhZ8hbQp9ra4XwIRZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963751; c=relaxed/simple; bh=AATao1D6lidjpskXGy5Ba1Q2c1dLwG1Gr0iVECdIp3I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pNLpmMu8iF71pTFqRnV6stM5vPQFTE1dQJQvUsAyNU81ZMJdFkIxkC4uXwXM66HvTCFBOjsM/qiOIzrlVNrLoXcidnos1FP5ljCjfmdNDHN7zthzhjj87l5FSigDKyLFWaTyJSk6yb8fzC25ZArB1PLqg38NDHjRQ02/knTrSmY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RnnIhqjO; arc=none smtp.client-ip=209.85.214.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RnnIhqjO" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20cceb8d8b4so4344915ad.1; Wed, 06 Nov 2024 23:15:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963749; x=1731568549; 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=4GjsxQ/i2qh7N2/wZ7xIogBkSPAFn+brlhd4b1PUcx0=; b=RnnIhqjOMjczDEDCxtoQbGDCFe5FTptpJ+PJ4pFmRFQFALzqKd5Pak4sU/8eaG/2oP zim91qQHRhRAZuH257pI90AHac5N4zXxFCVPUdsWH937G65sTNV3w2LmXj+TN0bLextK YDIJtHBb4djOSbKAJh2o5FTBsnZuSDfRTIFHMRulJs02M7/7xVoNY9DUtn0ArG+GsJag YUvP/dbGV00LqqbDCaYZHTHwiwuua3MLJz0vzK+yQGxvYd9bfjRiUQLc0PQ6v5rp42O1 56x28jJ86v9DF9yIXAFkt1ArLAC1ur5Hud/N1urD5yw1BJOPG/An+kPsHJKeNxEZbYmX x8OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963749; x=1731568549; 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=4GjsxQ/i2qh7N2/wZ7xIogBkSPAFn+brlhd4b1PUcx0=; b=Uu6jlUKs06HZCXmX6GiXnEbmbbtmhVED8Mxkwl/be/TJop9SL14AWXixWpwKBjUTv2 +W37QEf339b8FKw8KwUIVhWhhWkDuDekHufMdKTckwx4XMPcngJQ6itTwb3/nwuRlOcf IDaES7mGCI8/Xkp0yCpP3TYFZ3BKp2oG8dKDHOMLMOrHLpIq26LuNix6t2uhHLBvnuos 1QP9yfUOtqRKtX8s4O2YRhAa55s2d5ikT+Pw3W8uo3vyqbbETanemIdJZq2bPCYjB5SP nvdNBgylipXMv0VAOrxefDVb4aFL0FSDiIGP+rGv8FBJ5XavzhETF1kw53tq1xYjzHqh iJHQ== X-Forwarded-Encrypted: i=1; AJvYcCVEHFFgmE/E7xqdIyJ8rULUTLNmgATizIBucd+Dxcq5hMRQ0dhcAfSMNLu90kf5Kd/K9bn4JkpXYn2GiDQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyC9zCv5A9ioUyvN0ddDZmuJzXUvtwZVL2voa558qp2Ep7meSoW ab5zX+IDQfCo/lwnCJPoIp2LEt3lv7Hya2QkOyuV9Itozh/eebccLsjXCg== X-Google-Smtp-Source: AGHT+IH4RvxWUkNwdZma9LL9ggyjv9uD2eNgpFExnxBXbJTvi+8oJfsHloX7TSPqNz972h5nqfh5kw== X-Received: by 2002:a17:902:d510:b0:20b:a73b:3f5 with SMTP id d9443c01a7336-2117d18a67amr1009515ad.14.1730963748654; Wed, 06 Nov 2024 23:15:48 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:48 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] Input: ff-core - convert locking to guard notation Date: Wed, 6 Nov 2024 23:15:28 -0800 Message-ID: <20241107071538.195340-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use guard() and scoped_guard() notation instead of explicitly acquiring and releasing spinlocks and mutexes to simplify the code and ensure that all locks are released properly. Signed-off-by: Dmitry Torokhov --- drivers/input/ff-core.c | 71 +++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c index 609a5f01761b..eb01bcb69d00 100644 --- a/drivers/input/ff-core.c +++ b/drivers/input/ff-core.c @@ -93,7 +93,7 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, { struct ff_device *ff = dev->ff; struct ff_effect *old; - int ret = 0; + int error; int id; if (!test_bit(EV_FF, dev->evbit)) @@ -114,22 +114,20 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, } if (!test_bit(effect->type, ff->ffbit)) { - ret = compat_effect(ff, effect); - if (ret) - return ret; + error = compat_effect(ff, effect); + if (error) + return error; } - mutex_lock(&ff->mutex); + guard(mutex)(&ff->mutex); if (effect->id == -1) { for (id = 0; id < ff->max_effects; id++) if (!ff->effect_owners[id]) break; - if (id >= ff->max_effects) { - ret = -ENOSPC; - goto out; - } + if (id >= ff->max_effects) + return -ENOSPC; effect->id = id; old = NULL; @@ -137,30 +135,26 @@ int input_ff_upload(struct input_dev *dev, struct ff_effect *effect, } else { id = effect->id; - ret = check_effect_access(ff, id, file); - if (ret) - goto out; + error = check_effect_access(ff, id, file); + if (error) + return error; old = &ff->effects[id]; - if (!check_effects_compatible(effect, old)) { - ret = -EINVAL; - goto out; - } + if (!check_effects_compatible(effect, old)) + return -EINVAL; } - ret = ff->upload(dev, effect, old); - if (ret) - goto out; + error = ff->upload(dev, effect, old); + if (error) + return error; - spin_lock_irq(&dev->event_lock); - ff->effects[id] = *effect; - ff->effect_owners[id] = file; - spin_unlock_irq(&dev->event_lock); + scoped_guard(spinlock_irq, &dev->event_lock) { + ff->effects[id] = *effect; + ff->effect_owners[id] = file; + } - out: - mutex_unlock(&ff->mutex); - return ret; + return 0; } EXPORT_SYMBOL_GPL(input_ff_upload); @@ -178,17 +172,16 @@ static int erase_effect(struct input_dev *dev, int effect_id, if (error) return error; - spin_lock_irq(&dev->event_lock); - ff->playback(dev, effect_id, 0); - ff->effect_owners[effect_id] = NULL; - spin_unlock_irq(&dev->event_lock); + scoped_guard(spinlock_irq, &dev->event_lock) { + ff->playback(dev, effect_id, 0); + ff->effect_owners[effect_id] = NULL; + } if (ff->erase) { error = ff->erase(dev, effect_id); if (error) { - spin_lock_irq(&dev->event_lock); - ff->effect_owners[effect_id] = file; - spin_unlock_irq(&dev->event_lock); + scoped_guard(spinlock_irq, &dev->event_lock) + ff->effect_owners[effect_id] = file; return error; } @@ -210,16 +203,12 @@ static int erase_effect(struct input_dev *dev, int effect_id, int input_ff_erase(struct input_dev *dev, int effect_id, struct file *file) { struct ff_device *ff = dev->ff; - int ret; if (!test_bit(EV_FF, dev->evbit)) return -ENOSYS; - mutex_lock(&ff->mutex); - ret = erase_effect(dev, effect_id, file); - mutex_unlock(&ff->mutex); - - return ret; + guard(mutex)(&ff->mutex); + return erase_effect(dev, effect_id, file); } EXPORT_SYMBOL_GPL(input_ff_erase); @@ -239,13 +228,11 @@ int input_ff_flush(struct input_dev *dev, struct file *file) dev_dbg(&dev->dev, "flushing now\n"); - mutex_lock(&ff->mutex); + guard(mutex)(&ff->mutex); for (i = 0; i < ff->max_effects; i++) erase_effect(dev, i, file); - mutex_unlock(&ff->mutex); - return 0; } EXPORT_SYMBOL_GPL(input_ff_flush); From patchwork Thu Nov 7 07:15:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 841562 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.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 7FA0D195FE3; Thu, 7 Nov 2024 07:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963751; cv=none; b=bRa03JqZ71+/YJ3TXPyV4B2U4wCm6SJXOTc96QGHpCFS8pYDSsjyMYJAEKDxRH6S7NfMHOT43VKNTV2e3Suu2bG/c6IkIGAKxm7talRZIHQ9Ds6z9cfi7ufkcaXgscrvPMAVcJrf50vl+6D++iSHeP/+RtqcHaU+vP5/Kjan4oY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963751; c=relaxed/simple; bh=l73tBA6aq4wsRQHcuXI7BN7G/9crJqrrWDyE69fEVUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eeRsdRiP8OOjhbqZqxG7/yB06kDDyAcknLJn1i2wHkowbmM7D9hhoc08ehNgeLDHwCtuRmYJ3pb+yTTt94EBA0Zahzy0aFyQIEtPjbb3BlH6ptBEqeKUVkblCn6VKMB9khrYPD36lk3DdJlkbURSLdYrE254VyvO3tNuUdO7Mls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=daGOAn6G; arc=none smtp.client-ip=209.85.214.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="daGOAn6G" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20c9978a221so6830565ad.1; Wed, 06 Nov 2024 23:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963750; x=1731568550; 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=xo1+qs54rcJ3x+LX7xxfutqmwY8MMuXaKzLR6USPR4I=; b=daGOAn6Gr/pP5LZ01o5/PLaB7F/C9PpDmiRuGNfHHRXlFv0ysNP4SQ5XDFbezntNqh rcV77LPin0nzwDTf1aPBTi6VnfHgclFd+Uxnxb7V4Kia4Eu+F1FRuCcbJmo0u/ejzNwP mzMw87gHaljTEnyc1VtW3xYOww5qtrU9GvVRNfeM7gJ78BdbWZGQGHY8gjooMltWzsFJ SCSrgNCfQsVFx8W6tNMLYbG8IM/oqpSkU2FMhtuTLCDmvjwfLtZka+O8kLbkxUyXiG3m xmkv88Tyxn2cZg+6cKU1IS5e/zeEQoYVA7N0GalRRjlXvhkr3hs6Q3M7+C79TSw88lzd QQpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963750; x=1731568550; 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=xo1+qs54rcJ3x+LX7xxfutqmwY8MMuXaKzLR6USPR4I=; b=xT46c5QXGMI9SA3dd+5ChbTblXDjdXvu16gAP41ANKXDum0BaLKi91nqjE/LW+FCuN KwrtSaisxA3XpCaFBYl/6YVS0dvwRnB9wjIUfdWYIRessFA8/Ey2PgakPoNpE/nN03t4 gpN23B8bZr++kjo2OrM+VZaJqAoGNWQ5eNAM/UPoAfGYNPrDymuw0BrGftGcvwCPIclv knORmC+4iuTMlnJ6VVytoCtfHQyIwRJuuUty8DDHOuo53YMX1kNoH8bWrKztb6L/slTZ ZIR9FTQNEftcs3qSxsiWGQWXYxZp6WsJQ/Ph68lgUuw7UMIKf7YFWZup7sTJnZGDsgMD X9yg== X-Forwarded-Encrypted: i=1; AJvYcCX7uUYWALAqH2zCrfyJOYtFd/Gc06dHvpI6yKNbojvxYVxiZZHGAV9yZNLHRDWl1kH06TzwbEJOiN2HoMM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0urtD0S/c6BNqcVvAVrfEW/HATyCqmDFVQrdOwXmmJTFsZDCB SZXb7pKgRlE11gbX/Gh8FlfaIeybS20mtT88GNE5kR7Pwp0wjVgrenCe6w== X-Google-Smtp-Source: AGHT+IHi5cBBZki/PDrFlW/m+UKjANbVaYMwMbvVQbe/WHz/eJmds+pSVm4Zva12pu2CFbrA8R9ArQ== X-Received: by 2002:a17:902:d4c3:b0:20b:b0ab:4fc3 with SMTP id d9443c01a7336-210c6c934c1mr615273735ad.49.1730963749638; Wed, 06 Nov 2024 23:15:49 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:49 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] Input: ff-core - make use of __free() cleanup facility Date: Wed, 6 Nov 2024 23:15:29 -0800 Message-ID: <20241107071538.195340-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Annotate allocated memory with __free(kfree) to simplify the code and make sure memory is released appropriately. Signed-off-by: Dmitry Torokhov --- drivers/input/ff-core.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c index eb01bcb69d00..a235d2eb6b31 100644 --- a/drivers/input/ff-core.c +++ b/drivers/input/ff-core.c @@ -290,8 +290,6 @@ EXPORT_SYMBOL_GPL(input_ff_event); */ int input_ff_create(struct input_dev *dev, unsigned int max_effects) { - struct ff_device *ff; - size_t ff_dev_size; int i; if (!max_effects) { @@ -304,25 +302,20 @@ int input_ff_create(struct input_dev *dev, unsigned int max_effects) return -EINVAL; } - ff_dev_size = struct_size(ff, effect_owners, max_effects); - if (ff_dev_size == SIZE_MAX) /* overflow */ - return -EINVAL; - - ff = kzalloc(ff_dev_size, GFP_KERNEL); + struct ff_device *ff __free(kfree) = + kzalloc(struct_size(ff, effect_owners, max_effects), + GFP_KERNEL); if (!ff) return -ENOMEM; - ff->effects = kcalloc(max_effects, sizeof(struct ff_effect), - GFP_KERNEL); - if (!ff->effects) { - kfree(ff); + ff->effects = kcalloc(max_effects, sizeof(*ff->effects), GFP_KERNEL); + if (!ff->effects) return -ENOMEM; - } ff->max_effects = max_effects; mutex_init(&ff->mutex); - dev->ff = ff; + dev->ff = no_free_ptr(ff); dev->flush = input_ff_flush; dev->event = input_ff_event; __set_bit(EV_FF, dev->evbit); From patchwork Thu Nov 7 07:15:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 842562 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 1B3701993B5; Thu, 7 Nov 2024 07:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963753; cv=none; b=TjtFTglxe86EGHv1XPVz9Q2MYU8LH4QlOrsL3kmZcYmj32mgF+f6LYLmJ0ywhZfqbm/zz/7w9ACV7wZ9rwfPIm/SIfKuByBLZqdYjV2+32NCeyhaTGjsXpKCMyVB0YnpSKNpupcWT8KTLWnOiTUkzgvL9TpsYhmwuvrJyncXb0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963753; c=relaxed/simple; bh=L6g45plCb9kOyXyFczhKIRSi/3kWgV6hbUr+X8HZGS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T5I1drHZti6+MUH7ft1cZ7/isvOOPPrZICxBMOSxPJTr4BjBJnDcwopqL/G7ANoOQC/7UMxofzhAuKhMQkx4ZJ3Q3TeSO3dguKKFfWuhMrp4pO3mZRXgi88xlwcXHZEz0XwCdwEJJY1S3ghr5FZQQzmdNhxCtrbWjNd0pjy7KSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IjxODQR8; arc=none smtp.client-ip=209.85.215.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IjxODQR8" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7e6cbf6cd1dso472221a12.3; Wed, 06 Nov 2024 23:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963751; x=1731568551; 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=qP55KbfcJGjsyuftlPO9tdZ5NIYYO/K9vfzn7T/7FKI=; b=IjxODQR8Cz/J9O+K9T6a9iiaVp87g0ClO75XNgKL8Pr0wgmE+nEIZl0b7/VIIPBnXA mEXzqWQZef76Sef2tSrkYikixNnwedTnpn4hy0h5csQnW4GBxsOhKZKZ8F/f6qkFfxfp vFzR9Ep61q+94lXgXPD7iZhIxns2O+C3e55kDlTganwgylciKjkNGYZ0IXQCvZIjgIkR YEXm+6e7pVzVWeSB25mmItB2Y8IoABwQFIkOoQT7s4ji7DKpyoVe0qGetvp19FnI+lQt IkjMPUFsWaMckLp0t/8163sZbW+dmCn+IUlak+L/pzjxYcT1ElwR4WXiGA+O9QzY9Edt IRmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963751; x=1731568551; 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=qP55KbfcJGjsyuftlPO9tdZ5NIYYO/K9vfzn7T/7FKI=; b=OWx0lVTPUtvzUQpDyoLGo+hM7l4X9t9GPqlfHVh2ATMe9Fyg03cTuI4KzuC87ltTpC 3eev88DNc4Ziu3Cwl8wDkK09+1fkDDRRTeIl/jL+dgt74pHdjDUUtsbDSyJCIdhViNlo 1RCxVrWW6XvUKZwBe6rnBCkH781uz4Y4Mt/V1952AyFSb5nVdtHc6tl9XEvBwh+z8iar JSh4lYrRRoXKMI/3UV15v8GPlG5bYhHXFvI2fRu0WIZVKoChKqwubNvi5ABXMkJUma7/ 2cgg7hOc5h1jFktylb/CHUKtbXcC6gnpPbUUrYkkO5CKoAsNdhH0JQ1o5vSdUsD95kw4 8egw== X-Forwarded-Encrypted: i=1; AJvYcCUl8rgFhXcP0YZdzvw80l7pjZXhPCloKKuQYaVOXJ0De05PWvhQ+6WpIY0FaQp5QEN/5ijkHYQnuHemHUo=@vger.kernel.org X-Gm-Message-State: AOJu0YwH3k+sF1twqQ46XssMC6ZOANGvEHne84Dy4iJYu7JTI6i/BFdL mpnySGMaHSuABUC+4TyRzjHWW1NcPEaGzzX35UrIZbccZZxFO1aN X-Google-Smtp-Source: AGHT+IHrIIHEGLutXc60xyYKJ42NkDZxEiCObN13Abxkpv+RpPH1uKomQSllc+/Nq36iUiWPGo9+tA== X-Received: by 2002:a05:6a20:4321:b0:1db:dd9d:cd3f with SMTP id adf61e73a8af0-1dc17b2a593mr181031637.28.1730963750863; Wed, 06 Nov 2024 23:15:50 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:50 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] Input: ff-memless - convert locking to guard notation Date: Wed, 6 Nov 2024 23:15:30 -0800 Message-ID: <20241107071538.195340-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use guard() notation instead of explicitly acquiring and releasing spinlocks to simplify the code and ensure that all locks are released. Signed-off-by: Dmitry Torokhov --- drivers/input/ff-memless.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c index c321cdabd214..ec99c070a97c 100644 --- a/drivers/input/ff-memless.c +++ b/drivers/input/ff-memless.c @@ -401,13 +401,11 @@ static void ml_effect_timer(struct timer_list *t) { struct ml_device *ml = from_timer(ml, t, timer); struct input_dev *dev = ml->dev; - unsigned long flags; pr_debug("timer: updating effects\n"); - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); ml_play_effects(ml); - spin_unlock_irqrestore(&dev->event_lock, flags); } /* @@ -465,7 +463,7 @@ static int ml_ff_upload(struct input_dev *dev, struct ml_device *ml = dev->ff->private; struct ml_effect_state *state = &ml->states[effect->id]; - spin_lock_irq(&dev->event_lock); + guard(spinlock_irq)(&dev->event_lock); if (test_bit(FF_EFFECT_STARTED, &state->flags)) { __clear_bit(FF_EFFECT_PLAYING, &state->flags); @@ -477,8 +475,6 @@ static int ml_ff_upload(struct input_dev *dev, ml_schedule_timer(ml); } - spin_unlock_irq(&dev->event_lock); - return 0; } From patchwork Thu Nov 7 07:15:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 841561 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 DB4FB19AA5A; Thu, 7 Nov 2024 07:15:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963754; cv=none; b=B8/Z38E7YLgda0dRU+fv65H4ES5TEYLUANaJ37n1juJ4fQosJl1coP/+kBC3HqNbuPjjAPAQTOGpHqqjeY4eo/3VzRt8Ih8ThVVkD5rs34iWA0/H7WZ1ZLhIFc4eazx2ZsT2VOJDPYWHDT79fHEuHlqGRUFXEl+ZSvvzc5DHhRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963754; c=relaxed/simple; bh=Zo+DCnBbhJWA7vbbTjsU0Jb9DpzWBeiWzax+BwZ6J7c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uGRgZ5/IrBtdS9xbBq3atXCrsrrqq29DcdDT0m6D5wu2+CYPHvLmFX9KMiN1r/jhoVgjtU+GwWS/fuc0YPhcSDxOqgEcjSLsuUaaRnY4bqhUo7yMdxGHf4H3b5Ak7Uflx9ZBAWa92K1ZfJ7X+pUP0/+kpy/folPynMDnSADHjNE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JXuJQPPN; arc=none smtp.client-ip=209.85.214.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JXuJQPPN" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20caccadbeeso6683815ad.2; Wed, 06 Nov 2024 23:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963752; x=1731568552; 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=dVeVcpnNjSF95a/7QE2hgZhSNWlJ65lfFAfOVSCa8so=; b=JXuJQPPNtEi7zoD0yDM8FDPDCr91rZLaIaiexoZzU7eho3PFoL1CVdmMjKOBaECCzJ V3Ox1nfZJluxYwEthFJwgoGnb+5V/qy1kcyxD+IPDSgXcYjE3lN2/RvJIx+k/l37plO4 f0zBO+4N6aIyup995aed9VSa+mQqL+vurnNz4QNnCedXRWJ9ImAUwbGQI9kOtqyxbpVj Tgle7j+uwQpVo/zQWB2wPcAkaZodozlOOauaienb+65EnZUNC12oRx9UhkRjD55WIU9x EkTW/rs9hF5H/dN0I6MNJvGHV6H4Wpcwv+5x/XrfCUTA6Z5nybrjdNEVz6TIDkTr3mx/ Ultw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963752; x=1731568552; 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=dVeVcpnNjSF95a/7QE2hgZhSNWlJ65lfFAfOVSCa8so=; b=bHjiQzzAdLrYZwP03JHMyqiKYndjVwhpCKWJ6BEYPKA5iTkut8mraZ6slrCEPfcfph 8T/N0YM7If4nxBRV02+Xjw/gByr+i0N4idwO65o/pVdElG5xfO+OZ3RFuVlvSwb02fXX qx0Cr7gl2BexX04n5IltEWrJBqKNGNYNKRYbzhVRvgJpripQEF7I3UKLr7fwZ0rM3swK gWWL/BbyH9IOgrChgEIYRjLcInWVKFbVzo6ZqKedn2ltDwPnVQ5kw29eza1EWnH8s6E0 OypuEjNH/BJUIhus4/NXUItWmigBuT/WyzGwncB+idodFC2RHEasqPrEuQJO4ykTFMXg C1Gw== X-Forwarded-Encrypted: i=1; AJvYcCVvRC7ypgpTadhZchc/q0kMylWjsSpUXsDs2SVO4qkNGRHI60jG3bU3o5XyoPB2IG6PtMeZLiHilaMy5SA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxh87TcaD7TH8WaUbrfM7QHKCTpV8ml3cqVzgXr14socPZojtGx /ESUjMYKUmmNUFrQsbN/Lv6OaTD6liKtKVwWtHU6pKI1wvbCWNEs X-Google-Smtp-Source: AGHT+IFqKqQl/w+0kFYF09MRNz+yRZxuS63o0llDmhcnB8VJ5lyKqVdrLlwXBaGVz0/nqswJkvBCSw== X-Received: by 2002:a17:902:ce91:b0:20c:7720:59b8 with SMTP id d9443c01a7336-2117d20d025mr481805ad.6.1730963752114; Wed, 06 Nov 2024 23:15:52 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:51 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] Input: ff-memless - make use of __free() cleanup facility Date: Wed, 6 Nov 2024 23:15:31 -0800 Message-ID: <20241107071538.195340-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Annotate allocated memory with __free(kfree) to simplify the code and make sure memory is released appropriately. Signed-off-by: Dmitry Torokhov --- drivers/input/ff-memless.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c index ec99c070a97c..0bbeceb35545 100644 --- a/drivers/input/ff-memless.c +++ b/drivers/input/ff-memless.c @@ -503,12 +503,11 @@ static void ml_ff_destroy(struct ff_device *ff) int input_ff_create_memless(struct input_dev *dev, void *data, int (*play_effect)(struct input_dev *, void *, struct ff_effect *)) { - struct ml_device *ml; struct ff_device *ff; int error; int i; - ml = kzalloc(sizeof(struct ml_device), GFP_KERNEL); + struct ml_device *ml __free(kfree) = kzalloc(sizeof(*ml), GFP_KERNEL); if (!ml) return -ENOMEM; @@ -521,13 +520,11 @@ int input_ff_create_memless(struct input_dev *dev, void *data, set_bit(FF_GAIN, dev->ffbit); error = input_ff_create(dev, FF_MEMLESS_EFFECTS); - if (error) { - kfree(ml); + if (error) return error; - } ff = dev->ff; - ff->private = ml; + ff->private = no_free_ptr(ml); ff->upload = ml_ff_upload; ff->playback = ml_ff_playback; ff->set_gain = ml_ff_set_gain; From patchwork Thu Nov 7 07:15:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 842561 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.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 E80D5192D68; Thu, 7 Nov 2024 07:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963755; cv=none; b=aGj8MxewzAxw9iZBv0soK4DDbt9st2B+04QfYvxdSYiIPy0Gk4tmQYJhuHzDGwMFDmjNoySthC9Xeus7+KMbNkcqsr0Z5fsbw6iPcDku5lrDWHnhYpwb9efZK2w9xRRvVH08busSs8vclARNWNvL+f6+kRBSTB9Ez0ZYJaI2YYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963755; c=relaxed/simple; bh=vSGsIgFj+ICDtshl03yiA9Ruvbo9ycry/VM6cjk7TxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jiEoIr0REA79NcdOutVNvZlXMzRQYYXp8WpzZJ+rMVaS4w4v9Y0VIpLEftoKqzn1/lnmhglgPmdtSebfv/mthxoJjWKUW5cX6nBsBhOBS8y2yIyeHAhr+K7DB0Xleih7/OBhYDW6knyiB6K/MkJQ/6ytfbu9dkA1VnQuJ/NYu60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iebeOqrf; arc=none smtp.client-ip=209.85.214.182 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iebeOqrf" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2114214c63eso5154905ad.3; Wed, 06 Nov 2024 23:15:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963753; x=1731568553; 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=PnC/CEEyFrp0NngtmFGLRHAHLJYkgnLyAsiePHD2C78=; b=iebeOqrfTv81bseUxdawihwHv4eufkASKkJte1TANaC897yED0NTpLRTD5TulGTYoP SOosn0FPkrZYm85fuHHxKd/qOVpEB5V7GQbUqRsruOxrtSq9q5KHmQvXqEZJOLxcAewi +vj90I9NWSkXAdQS8nGMiTeTvWV7iAQwJ/UwOw9rNLq/vdHgbj6PjRPQ1vBXWI8+zbF2 K3X8eVT5kRl9Y3IhHPoh7vOmakTOb0pephGRhg6t1GZ53xcvvHy2sGKY0ZEm6HR11KER bl7DNdqwzo2Zus/xL9FLN1rMd6/dAgWQqalszeypvH7ScZEj4YCHmhZCmKsV5HkTodg3 3qwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963753; x=1731568553; 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=PnC/CEEyFrp0NngtmFGLRHAHLJYkgnLyAsiePHD2C78=; b=uWmkapV63YNuPqOq6EpFiNZ96vDp9FJt8yva6PYZV4ZawT3g+zGgYD/TTUbXY0yNNl 5uI+JFv+LKbnKz40SS0kB/Mmd7TcxnSBpJmEUKjnxz9bWnPmL1DZwIHhRTmDhIzibu64 OnZhfmdMNvioEQT34+9QpjVMElQGIMUaqe84bnlmzyoVvpybUYzkMmQdj85/uUWSd0Y1 YQ5DT30L23dUD4TdNBvpfmN83b9OFRNswh02qxS2ulActj3H44wK4f9BM/fseoOhgxg6 ev82ixgams3a4TJE6TUdd80+Ms+JBjq8Haly+tHAroT6+UpD/+S+Ldx4hlt+9vihtHT0 coGA== X-Forwarded-Encrypted: i=1; AJvYcCVUoTsvqyGqOLvYT75a+fgGn+t6dw9OFWzpeMzgZXkULIZUi1aXZxZrw8Q0GIeDpMFpcjxCtm13IUmJFGc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8+qLWrTT6rZdjac6IgQICpkfSYoR6Rvxj3gjPs5CR78vSpHbK 5dgjG+xDOmHh6iJOK4oI4+h/Q5jwAUorpI9PWyimxWn4OxDnYDDe X-Google-Smtp-Source: AGHT+IEhFeUz4ZF4MaeF36cLnGA7X9ZBT+QQ7fuQ5jsEZtThVOWKYSnBqfhMYr5D9o7wROxUQUQTcw== X-Received: by 2002:a17:903:40c9:b0:20c:c694:f6c6 with SMTP id d9443c01a7336-210c6c52417mr563066245ad.49.1730963753191; Wed, 06 Nov 2024 23:15:53 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:52 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] Input: mt - convert locking to guard notation Date: Wed, 6 Nov 2024 23:15:32 -0800 Message-ID: <20241107071538.195340-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use guard() notation instead of explicitly acquiring and releasing spinlocks to simplify the code and ensure that all locks are released. Signed-off-by: Dmitry Torokhov --- drivers/input/input-mt.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c index 6b04a674f832..45e41fc9059c 100644 --- a/drivers/input/input-mt.c +++ b/drivers/input/input-mt.c @@ -285,14 +285,10 @@ void input_mt_drop_unused(struct input_dev *dev) struct input_mt *mt = dev->mt; if (mt) { - unsigned long flags; - - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); __input_mt_drop_unused(dev, mt); mt->frame++; - - spin_unlock_irqrestore(&dev->event_lock, flags); } } EXPORT_SYMBOL(input_mt_drop_unused); @@ -339,11 +335,8 @@ void input_mt_sync_frame(struct input_dev *dev) return; if (mt->flags & INPUT_MT_DROP_UNUSED) { - unsigned long flags; - - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); __input_mt_drop_unused(dev, mt); - spin_unlock_irqrestore(&dev->event_lock, flags); } if ((mt->flags & INPUT_MT_POINTER) && !(mt->flags & INPUT_MT_SEMI_MT)) From patchwork Thu Nov 7 07:15:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 841560 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 EEA3A1D7985; Thu, 7 Nov 2024 07:15:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963756; cv=none; b=ern0RhietmcxTuhdpPOB7Q5GWQJ8ZQbl2ynCURaUJNtvCKqV4qTp25K/QqHlhncFzl6INbqtB84PRL8WRmq11zs0WnYsjSNzF4p0kjyir/HUJg9IYMMo4akmwedyG8yJ9c4Gpm52tIJqz8nLkTYkS4oN+jLOE5YP/HJDNU33fFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963756; c=relaxed/simple; bh=oo2cU78lvM/dSXVwa6N8vfF04jRbKQLqkGmyWl+lqnU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P7sEEYwSN/hneLvIHdwcrMRxeMzF5D/Mps0cA4qzCX0z51XB1eOnzpa+Yy/N9/yDd/8mQAKPPbskWVbs6IRgdEt4+BSsstgIhaiF0PGjAkYo+ViVqnYqPK7g1EsWprlyrIz9E2Bba3ZnNYfK6FzKiD3KKzRFkdYVvPWCsA7d7MM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LN+euxAR; arc=none smtp.client-ip=209.85.215.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LN+euxAR" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7f3f1849849so512015a12.1; Wed, 06 Nov 2024 23:15:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963754; x=1731568554; 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=F7OUSy9uYp7qD1AAKZu58DukLp8nWw6fpBK5gLOx6XI=; b=LN+euxARFqPGehDvwsVmh9vj6yogz4LojC3jadSYmDZhO258HGO3fAPc+FDmNbFmjM cnyjEBxJgtwUpJEUIo8DiHjcD+UnInwzOEKBxU9+56rBa77k/AnWq6Xgw7elv1Pqe7az aHawAhLEkGVCL9yrkRtdTY539ubSsYmU6izEBMzUdXux5MPbxZw+M/XOfiWNQxDudm3O WRFLumw4npNOCCawSKWaXTLxwwwfmrPUUME9DHSDPWAKeJ3jWoX1C34FGeaO6BeJaNb+ qDy3oUw6Cd2rrq2kNFjveDDBHIZ5O9F85eGltKqYBDoTE2xQ70fSpo7RQLucRDpunWL9 LnbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963754; x=1731568554; 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=F7OUSy9uYp7qD1AAKZu58DukLp8nWw6fpBK5gLOx6XI=; b=rmi/84SGhyHg/y3gW64wMFRqI/oZ+XhkEDOizCkeZvuW6cOe2OlUI1aahKeiTVDB3C CT6RDSuaPdBFC92AC/7Bh9Ef6RfP8K6mer37w0a419yQIVKFYTiA/HC1spSHl3EykL6R LxOb0IZsb73IF3jns/Kkh+1t4T1nnozZcWv88ug2shFpGQTRqu8w+R5zVxQ/vt4L4Uh3 L6nRC8KXTztlG7fOzmOOC2tA3yodXtDATvNgV+ioenrgB2LQ0mk6oBesWTooPE0nt4GA 45UN8EJymRzIJv4f4dnBKUO8lUsWt234lvvF6OMfOWj9GiVk8Y5AHXKDN+ADAAnQUHOR gVdQ== X-Forwarded-Encrypted: i=1; AJvYcCVrEllwMrxTBKeqm3vasMkCN5NzR84QeAsXqZaSIc9VSCDd4l79HszsIoMyGIe3OhAfhAmd3Xpz8SC8zPE=@vger.kernel.org X-Gm-Message-State: AOJu0YxVZ37TVM7uWwv8HdJJV2BzQUn06+SMKxb7IR4MYBa4cTx1j1C0 mJJtZLTXBy0dJz1FbOO3a7V8m1vWgYYWHS/sQC9LKhP0SBf1bx9I X-Google-Smtp-Source: AGHT+IHyLhW2rIJPbcTIf9ImWTwUM6iq5Za9KbxHUOUrPqjpxRvFE8xWd3W+IQfvCyIVpy5YuzG9jQ== X-Received: by 2002:a05:6a21:6d85:b0:1d9:fbc:457c with SMTP id adf61e73a8af0-1dc17b2a8cdmr229791637.36.1730963754241; Wed, 06 Nov 2024 23:15:54 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:53 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] Input: mt - make use of __free() cleanup facility Date: Wed, 6 Nov 2024 23:15:33 -0800 Message-ID: <20241107071538.195340-7-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Annotate allocated memory with __free(kfree) to simplify the code and make sure memory is released appropriately. Signed-off-by: Dmitry Torokhov --- drivers/input/input-mt.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c index 45e41fc9059c..337006dd9dcf 100644 --- a/drivers/input/input-mt.c +++ b/drivers/input/input-mt.c @@ -39,20 +39,20 @@ static void copy_abs(struct input_dev *dev, unsigned int dst, unsigned int src) int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, unsigned int flags) { - struct input_mt *mt = dev->mt; - int i; - if (!num_slots) return 0; - if (mt) - return mt->num_slots != num_slots ? -EINVAL : 0; + + if (dev->mt) + return dev->mt->num_slots != num_slots ? -EINVAL : 0; + /* Arbitrary limit for avoiding too large memory allocation. */ if (num_slots > 1024) return -EINVAL; - mt = kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL); + struct input_mt *mt __free(kfree) = + kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL); if (!mt) - goto err_mem; + return -ENOMEM; mt->num_slots = num_slots; mt->flags = flags; @@ -86,21 +86,18 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, unsigned int n2 = num_slots * num_slots; mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL); if (!mt->red) - goto err_mem; + return -ENOMEM; } /* Mark slots as 'inactive' */ - for (i = 0; i < num_slots; i++) + for (unsigned int i = 0; i < num_slots; i++) input_mt_set_value(&mt->slots[i], ABS_MT_TRACKING_ID, -1); /* Mark slots as 'unused' */ mt->frame = 1; - dev->mt = mt; + dev->mt = no_free_ptr(mt); return 0; -err_mem: - kfree(mt); - return -ENOMEM; } EXPORT_SYMBOL(input_mt_init_slots); From patchwork Thu Nov 7 07:15:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 842560 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.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 2757E1953BD; Thu, 7 Nov 2024 07:15:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963757; cv=none; b=eYeTWtMIf1mnWRExw6nY40DeX319RWtolNNr4gIGUwG2DEEtTTgOBRXX38pR2r+eck4wgROx35IBrqfCru8LWEhSJsLa5XtF8VU3Z9EQiIqybmVWqkDfgL2dVg9da/q4HvHRAUSG8zpqCifGm3W8f5oaxCjAMQeTc46D4t8PXNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963757; c=relaxed/simple; bh=gZg3E9TEbMgr0TWfCW02bIVmzctcKC1CnuaUU7RaWpE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F54sN6BwrsFmLMtJJEZAG5Obeshnss3ukYQ5GgM0HRCuwX2161JBaw/bt5o+L2I8OqRMT+eneV1jH3LEQ+ORlZ0pIFvgU4Y/51CTw9v0k7ap/Pvgbat9A3LUqsfcFNeSfuLjU9srDJwTWrSN8udp99dJWq3zJbWpOFRW8K0upaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HljgRCNF; arc=none smtp.client-ip=209.85.214.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HljgRCNF" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-20cf6eea3c0so6857935ad.0; Wed, 06 Nov 2024 23:15:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963755; x=1731568555; 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=NMYrbEqWbCEht0e4TRSS4DBG5we6uEz9lb8VuRuD1JY=; b=HljgRCNFoCu9My23Q3Bd1QnpkEU8rj+kmDqCCXXYpmZJ5GTIqEX6koudhF52Wdv2/s ixYK7cxktBVzagJ/XKGgrg4RADDzctOlWWwSmy917EDVV80h3baooPVJp/PZSh8phMOQ 1PmuvMXtvSCcAvISItpZVV8eOZ/d3e3LVl1TCXPAJTZrBc5esnJ+cfrJkVhMn7c3AKyM mzGqYhCUceAd4TU9bZegn0n2TFwer5S16aUvxLHS0cgd+f8irWe5Umd8Jyi0zZ+otpm8 68RYtyCEI1/cb4nRc1+7HqpVB4xwqcOTFJP8RLlCQwAa3VlCn3uGv5QTnATsbjY8851o iyAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963755; x=1731568555; 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=NMYrbEqWbCEht0e4TRSS4DBG5we6uEz9lb8VuRuD1JY=; b=AVLv9nzrN5NDeLuJ++kCoVerlyd4AuOCg6MTTxaWTiz+YJgBRcdjimVQvXi91bu3zl lLsWL6kMqbF1ttd/MglwnlRqjBXK7XPjo0CqgR+w/+gUHHpryVvoAfZXedYxEKOVaYFb nMMj139Wl5aT5rnUJoemWYbuxSpP+SbGiUqMJmoM8sCRPjMbcIO1bJcK53RXO2M1+69T TLkhtB4p6+4eZ3xsWNOVAs7z5TpcEiAt9zr9Zyemll/D3935SjFK5DvR3NBekcrXOH+C sbmNjT+fbQJey2z5gP3Aa7c+21EuoyrZbsXMtN6neUBr378Yq3u18QDJWOdyxNil0p2N tNnw== X-Forwarded-Encrypted: i=1; AJvYcCW80X+Y/HBEzBr5ypfRSL5mfwRbxLVPwOjKNOvFixDbNFAvc0QWaJx60mPhKzdJnHYK0jEyGL4cupz/oNc=@vger.kernel.org X-Gm-Message-State: AOJu0YyVGAks+oC2wyKIxqEUDaQnLBdo6l7bC7tq+80kcPFEFqQN1vOO nWAtLFO8xoZMf55tiQSyW1LWHhZHzEANSLfPOl4xM+wEc3ITfP9J X-Google-Smtp-Source: AGHT+IHqnRb0PLT8SwT3u/Nr4etLOltYCJVDi7KRvMS1jlvFJW0ZVLCUUFQvESc7nGZhBcRpBzaEhw== X-Received: by 2002:a17:902:d485:b0:20c:7c09:b2ac with SMTP id d9443c01a7336-210c6c5db72mr555605805ad.52.1730963755269; Wed, 06 Nov 2024 23:15:55 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:54 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] Input: poller - convert locking to guard notation Date: Wed, 6 Nov 2024 23:15:34 -0800 Message-ID: <20241107071538.195340-8-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use guard() notation instead of explicitly acquiring and releasing mutex to simplify the code and ensure that it is released. Signed-off-by: Dmitry Torokhov --- drivers/input/input-poller.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/input/input-poller.c b/drivers/input/input-poller.c index 688e3cb1c2a0..9c57713a6151 100644 --- a/drivers/input/input-poller.c +++ b/drivers/input/input-poller.c @@ -162,7 +162,7 @@ static ssize_t input_dev_set_poll_interval(struct device *dev, if (interval > poller->poll_interval_max) return -EINVAL; - mutex_lock(&input->mutex); + guard(mutex)(&input->mutex); poller->poll_interval = interval; @@ -172,8 +172,6 @@ static ssize_t input_dev_set_poll_interval(struct device *dev, input_dev_poller_queue_work(poller); } - mutex_unlock(&input->mutex); - return count; } From patchwork Thu Nov 7 07:15:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 841559 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 349EC1DB349; Thu, 7 Nov 2024 07:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963759; cv=none; b=SlAqP1xdyslMJq6NClFDaQ0XzO2RjjLztXt++zJuxBvcuKcwMqcfvZ/CIVar9B35SLKRDfqash2M6y4igXrV5hLgqfFPT3PmvgYJl82hfENJRAwjMRKtUnl/YPJ8pNsvH8S4+9XxqrD0/Qh9moYPVIh8t4G1G8oCsw8NtuQiftQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730963759; c=relaxed/simple; bh=/RUaVUpDQ7T5tTxPo6zLJB7T4fE2ssNRXsspSUPn3E8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMDnd12uNDn28mEU5sDcuQSz1n53ZUk6k/r+bl3pyZtfHAQhqBbOxFiZxqUI5AYqevTpiCM6hAzBw4/nG0W41QNvOjYaz+d+ZO2/9Wor0Ad85TAYtpDy8gj6bG757NqRKTMgQ47kH2GxbTaMOZxCCHJqnQZiUZKPE8+/c8R1KRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JY0Gfk18; arc=none smtp.client-ip=209.85.214.173 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JY0Gfk18" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20c7edf2872so14730975ad.1; Wed, 06 Nov 2024 23:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730963756; x=1731568556; 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=ytENwwVCnR/pe/wHV6/c4qrD5DdYDBL06kZXp7xsQIQ=; b=JY0Gfk183evf9l92NCUk3Y7XdgIzFSfQx4rJgm7/rGPPRsvaqAMTODjCrOPLIZ+oLE 87VWwWuzkRIY59gTDzXoYnbVYE2/ndtGNsovUsi6yJ9KTuyozydB7vczZSb3vyReyh38 omFj2W4VQBQr/J/TsA1og2ax7rliwR5D5o+mH3txaJDXpnoWydM7Gf3atwUemeM4wlaj O/IybSWLhXL+6S+6wwdjlBCDeWO2DjueySNw2LSD9CnSl5pRRjanpoi0H6dyTllHanov 3osdi0mgkpOLMNnKW87ABnRJTdM3pg5ncGAKMYOaQUF0VmddTPJEOKO29wM06/0g1Dy/ S9rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730963756; x=1731568556; 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=ytENwwVCnR/pe/wHV6/c4qrD5DdYDBL06kZXp7xsQIQ=; b=ABYc1af/SYeZfqWG7yjAt6nVKEJNpNXBzkR8SiGMZBW33eM1d7bLSrHvdRqmBZAOS6 I67cdYRFRHyn+wuvlahsJIRp7TXsAZT5xS54sGbF7HNYQeaSfKGph4URWpubBa7AfkAY K6C/TVJRwzQY/dwuegxYhmwQwYCrVsuf+dBsnMvNhnDHUbne91Xq5+7I0mD95siL+XfR 1no4KI5SBHb43hbbCKlJsOLjQzsn8vSbHnJTFA/tdWOh+y2VGHHikQLf1DOyLNonuEH0 ihe50bUlWGr53N6P1Sc8b5GHNrycwmwwSW2ci4tRJB0fYgiOvWFIFUY7XrknVYVnN/TN XMuw== X-Forwarded-Encrypted: i=1; AJvYcCWvTAapfjz5ALXVw80i8b4drrPJkIYs+TgimowG/QTlwmlWCE7Ux5Rj4XlDEMLbCagMKmRbspoSunbVctU=@vger.kernel.org X-Gm-Message-State: AOJu0YyNkRDwuOAkNzOTkaxTgsUM8n6QAX9Xi9avc+UE3CZmM1PR+OqG sztnG3RxtH4Ro8g5l0ZUDXjfEnWPgnaqbCDWdvbAIziT9mjuszmMCvL0og== X-Google-Smtp-Source: AGHT+IGAstm/8rheuADwv1sysMP2AgMwEVXoCVKFTdZdwpFnT2jAg1u1jWT8D/u2FJnBjgP2K6vgPA== X-Received: by 2002:a17:902:e54e:b0:20c:8f98:5dbb with SMTP id d9443c01a7336-2117d1a208dmr860775ad.16.1730963756331; Wed, 06 Nov 2024 23:15:56 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:e838:5f55:2b1d:de33]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177e58399sm5703905ad.196.2024.11.06.23.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 23:15:55 -0800 (PST) From: Dmitry Torokhov To: Jiri Kosina , Benjamin Tissoires , Hans de Goede Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] Input: use guard notation in input core Date: Wed, 6 Nov 2024 23:15:35 -0800 Message-ID: <20241107071538.195340-9-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog In-Reply-To: <20241107071538.195340-1-dmitry.torokhov@gmail.com> References: <20241107071538.195340-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Switch input core to use "guard" notation when acquiring spinlocks and mutexes to simplify the code and ensure that locks are automatically released when control leaves critical section. Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 339 ++++++++++++++++-------------------------- 1 file changed, 131 insertions(+), 208 deletions(-) diff --git a/drivers/input/input.c b/drivers/input/input.c index fd9d40286b75..d73231e695f8 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -115,23 +115,23 @@ static void input_pass_values(struct input_dev *dev, lockdep_assert_held(&dev->event_lock); - rcu_read_lock(); + scoped_guard(rcu) { + handle = rcu_dereference(dev->grab); + if (handle) { + count = handle->handle_events(handle, vals, count); + break; + } - handle = rcu_dereference(dev->grab); - if (handle) { - count = handle->handle_events(handle, vals, count); - } else { - list_for_each_entry_rcu(handle, &dev->h_list, d_node) + list_for_each_entry_rcu(handle, &dev->h_list, d_node) { if (handle->open) { count = handle->handle_events(handle, vals, count); if (!count) break; } + } } - rcu_read_unlock(); - /* trigger auto repeat for key events */ if (test_bit(EV_REP, dev->evbit) && test_bit(EV_KEY, dev->evbit)) { for (v = vals; v != vals + count; v++) { @@ -390,13 +390,9 @@ void input_handle_event(struct input_dev *dev, void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) { - unsigned long flags; - if (is_event_supported(type, dev->evbit, EV_MAX)) { - - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); input_handle_event(dev, type, code, value); - spin_unlock_irqrestore(&dev->event_lock, flags); } } EXPORT_SYMBOL(input_event); @@ -417,18 +413,15 @@ void input_inject_event(struct input_handle *handle, { struct input_dev *dev = handle->dev; struct input_handle *grab; - unsigned long flags; if (is_event_supported(type, dev->evbit, EV_MAX)) { - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); + guard(rcu)(); - rcu_read_lock(); grab = rcu_dereference(dev->grab); if (!grab || grab == handle) input_handle_event(dev, type, code, value); - rcu_read_unlock(); - spin_unlock_irqrestore(&dev->event_lock, flags); } } EXPORT_SYMBOL(input_inject_event); @@ -526,22 +519,15 @@ EXPORT_SYMBOL(input_copy_abs); int input_grab_device(struct input_handle *handle) { struct input_dev *dev = handle->dev; - int retval; - retval = mutex_lock_interruptible(&dev->mutex); - if (retval) - return retval; + scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { + if (dev->grab) + return -EBUSY; - if (dev->grab) { - retval = -EBUSY; - goto out; + rcu_assign_pointer(dev->grab, handle); } - rcu_assign_pointer(dev->grab, handle); - - out: - mutex_unlock(&dev->mutex); - return retval; + return 0; } EXPORT_SYMBOL(input_grab_device); @@ -576,9 +562,8 @@ void input_release_device(struct input_handle *handle) { struct input_dev *dev = handle->dev; - mutex_lock(&dev->mutex); + guard(mutex)(&dev->mutex); __input_release_device(handle); - mutex_unlock(&dev->mutex); } EXPORT_SYMBOL(input_release_device); @@ -592,67 +577,57 @@ EXPORT_SYMBOL(input_release_device); int input_open_device(struct input_handle *handle) { struct input_dev *dev = handle->dev; - int retval; - - retval = mutex_lock_interruptible(&dev->mutex); - if (retval) - return retval; - - if (dev->going_away) { - retval = -ENODEV; - goto out; - } + int error; - handle->open++; + scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { + if (dev->going_away) + return -ENODEV; - if (handle->handler->passive_observer) - goto out; + handle->open++; - if (dev->users++ || dev->inhibited) { - /* - * Device is already opened and/or inhibited, - * so we can exit immediately and report success. - */ - goto out; - } + if (handle->handler->passive_observer) + return 0; - if (dev->open) { - retval = dev->open(dev); - if (retval) { - dev->users--; - handle->open--; + if (dev->users++ || dev->inhibited) { /* - * Make sure we are not delivering any more events - * through this handle + * Device is already opened and/or inhibited, + * so we can exit immediately and report success. */ - synchronize_rcu(); - goto out; + return 0; } - } - if (dev->poller) - input_dev_poller_start(dev->poller); + if (dev->open) { + error = dev->open(dev); + if (error) { + dev->users--; + handle->open--; + /* + * Make sure we are not delivering any more + * events through this handle. + */ + synchronize_rcu(); + return error; + } + } - out: - mutex_unlock(&dev->mutex); - return retval; + if (dev->poller) + input_dev_poller_start(dev->poller); + } + + return 0; } EXPORT_SYMBOL(input_open_device); int input_flush_device(struct input_handle *handle, struct file *file) { struct input_dev *dev = handle->dev; - int retval; - retval = mutex_lock_interruptible(&dev->mutex); - if (retval) - return retval; - - if (dev->flush) - retval = dev->flush(dev, file); + scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { + if (dev->flush) + return dev->flush(dev, file); + } - mutex_unlock(&dev->mutex); - return retval; + return 0; } EXPORT_SYMBOL(input_flush_device); @@ -667,7 +642,7 @@ void input_close_device(struct input_handle *handle) { struct input_dev *dev = handle->dev; - mutex_lock(&dev->mutex); + guard(mutex)(&dev->mutex); __input_release_device(handle); @@ -688,8 +663,6 @@ void input_close_device(struct input_handle *handle) */ synchronize_rcu(); } - - mutex_unlock(&dev->mutex); } EXPORT_SYMBOL(input_close_device); @@ -726,11 +699,10 @@ static void input_disconnect_device(struct input_dev *dev) * not to protect access to dev->going_away but rather to ensure * that there are no threads in the middle of input_open_device() */ - mutex_lock(&dev->mutex); - dev->going_away = true; - mutex_unlock(&dev->mutex); + scoped_guard(mutex, &dev->mutex) + dev->going_away = true; - spin_lock_irq(&dev->event_lock); + guard(spinlock_irq)(&dev->event_lock); /* * Simulate keyup events for all pressed keys so that handlers @@ -743,8 +715,6 @@ static void input_disconnect_device(struct input_dev *dev) list_for_each_entry(handle, &dev->h_list, d_node) handle->open = 0; - - spin_unlock_irq(&dev->event_lock); } /** @@ -901,14 +871,9 @@ static int input_default_setkeycode(struct input_dev *dev, */ int input_get_keycode(struct input_dev *dev, struct input_keymap_entry *ke) { - unsigned long flags; - int retval; + guard(spinlock_irqsave)(&dev->event_lock); - spin_lock_irqsave(&dev->event_lock, flags); - retval = dev->getkeycode(dev, ke); - spin_unlock_irqrestore(&dev->event_lock, flags); - - return retval; + return dev->getkeycode(dev, ke); } EXPORT_SYMBOL(input_get_keycode); @@ -923,18 +888,17 @@ EXPORT_SYMBOL(input_get_keycode); int input_set_keycode(struct input_dev *dev, const struct input_keymap_entry *ke) { - unsigned long flags; unsigned int old_keycode; - int retval; + int error; if (ke->keycode > KEY_MAX) return -EINVAL; - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); - retval = dev->setkeycode(dev, ke, &old_keycode); - if (retval) - goto out; + error = dev->setkeycode(dev, ke, &old_keycode); + if (error) + return error; /* Make sure KEY_RESERVED did not get enabled. */ __clear_bit(KEY_RESERVED, dev->keybit); @@ -962,10 +926,7 @@ int input_set_keycode(struct input_dev *dev, EV_SYN, SYN_REPORT, 1); } - out: - spin_unlock_irqrestore(&dev->event_lock, flags); - - return retval; + return 0; } EXPORT_SYMBOL(input_set_keycode); @@ -1802,26 +1763,21 @@ static void input_dev_toggle(struct input_dev *dev, bool activate) */ void input_reset_device(struct input_dev *dev) { - unsigned long flags; - - mutex_lock(&dev->mutex); - spin_lock_irqsave(&dev->event_lock, flags); + guard(mutex)(&dev->mutex); + guard(spinlock_irqsave)(&dev->event_lock); input_dev_toggle(dev, true); if (input_dev_release_keys(dev)) input_handle_event(dev, EV_SYN, SYN_REPORT, 1); - - spin_unlock_irqrestore(&dev->event_lock, flags); - mutex_unlock(&dev->mutex); } EXPORT_SYMBOL(input_reset_device); static int input_inhibit_device(struct input_dev *dev) { - mutex_lock(&dev->mutex); + guard(mutex)(&dev->mutex); if (dev->inhibited) - goto out; + return 0; if (dev->users) { if (dev->close) @@ -1830,54 +1786,50 @@ static int input_inhibit_device(struct input_dev *dev) input_dev_poller_stop(dev->poller); } - spin_lock_irq(&dev->event_lock); - input_mt_release_slots(dev); - input_dev_release_keys(dev); - input_handle_event(dev, EV_SYN, SYN_REPORT, 1); - input_dev_toggle(dev, false); - spin_unlock_irq(&dev->event_lock); + scoped_guard(spinlock_irq, &dev->event_lock) { + input_mt_release_slots(dev); + input_dev_release_keys(dev); + input_handle_event(dev, EV_SYN, SYN_REPORT, 1); + input_dev_toggle(dev, false); + } dev->inhibited = true; -out: - mutex_unlock(&dev->mutex); return 0; } static int input_uninhibit_device(struct input_dev *dev) { - int ret = 0; + int error; - mutex_lock(&dev->mutex); + guard(mutex)(&dev->mutex); if (!dev->inhibited) - goto out; + return 0; if (dev->users) { if (dev->open) { - ret = dev->open(dev); - if (ret) - goto out; + error = dev->open(dev); + if (error) + return error; } if (dev->poller) input_dev_poller_start(dev->poller); } dev->inhibited = false; - spin_lock_irq(&dev->event_lock); - input_dev_toggle(dev, true); - spin_unlock_irq(&dev->event_lock); -out: - mutex_unlock(&dev->mutex); - return ret; + scoped_guard(spinlock_irq, &dev->event_lock) + input_dev_toggle(dev, true); + + return 0; } static int input_dev_suspend(struct device *dev) { struct input_dev *input_dev = to_input_dev(dev); - spin_lock_irq(&input_dev->event_lock); + guard(spinlock_irq)(&input_dev->event_lock); /* * Keys that are pressed now are unlikely to be @@ -1889,8 +1841,6 @@ static int input_dev_suspend(struct device *dev) /* Turn off LEDs and sounds, if any are active. */ input_dev_toggle(input_dev, false); - spin_unlock_irq(&input_dev->event_lock); - return 0; } @@ -1898,13 +1848,11 @@ static int input_dev_resume(struct device *dev) { struct input_dev *input_dev = to_input_dev(dev); - spin_lock_irq(&input_dev->event_lock); + guard(spinlock_irq)(&input_dev->event_lock); /* Restore state of LEDs and sounds, if any were active. */ input_dev_toggle(input_dev, true); - spin_unlock_irq(&input_dev->event_lock); - return 0; } @@ -1912,7 +1860,7 @@ static int input_dev_freeze(struct device *dev) { struct input_dev *input_dev = to_input_dev(dev); - spin_lock_irq(&input_dev->event_lock); + guard(spinlock_irq)(&input_dev->event_lock); /* * Keys that are pressed now are unlikely to be @@ -1921,8 +1869,6 @@ static int input_dev_freeze(struct device *dev) if (input_dev_release_keys(input_dev)) input_handle_event(input_dev, EV_SYN, SYN_REPORT, 1); - spin_unlock_irq(&input_dev->event_lock); - return 0; } @@ -1930,13 +1876,11 @@ static int input_dev_poweroff(struct device *dev) { struct input_dev *input_dev = to_input_dev(dev); - spin_lock_irq(&input_dev->event_lock); + guard(spinlock_irq)(&input_dev->event_lock); /* Turn off LEDs and sounds, if any are active. */ input_dev_toggle(input_dev, false); - spin_unlock_irq(&input_dev->event_lock); - return 0; } @@ -2277,18 +2221,16 @@ static void __input_unregister_device(struct input_dev *dev) input_disconnect_device(dev); - mutex_lock(&input_mutex); - - list_for_each_entry_safe(handle, next, &dev->h_list, d_node) - handle->handler->disconnect(handle); - WARN_ON(!list_empty(&dev->h_list)); + scoped_guard(mutex, &input_mutex) { + list_for_each_entry_safe(handle, next, &dev->h_list, d_node) + handle->handler->disconnect(handle); + WARN_ON(!list_empty(&dev->h_list)); - del_timer_sync(&dev->timer); - list_del_init(&dev->node); + del_timer_sync(&dev->timer); + list_del_init(&dev->node); - input_wakeup_procfs_readers(); - - mutex_unlock(&input_mutex); + input_wakeup_procfs_readers(); + } device_del(&dev->dev); } @@ -2311,9 +2253,8 @@ static void devm_input_device_unregister(struct device *dev, void *res) static void input_repeat_key(struct timer_list *t) { struct input_dev *dev = from_timer(dev, t, timer); - unsigned long flags; - spin_lock_irqsave(&dev->event_lock, flags); + guard(spinlock_irqsave)(&dev->event_lock); if (!dev->inhibited && test_bit(dev->repeat_key, dev->key) && @@ -2327,8 +2268,6 @@ static void input_repeat_key(struct timer_list *t) mod_timer(&dev->timer, jiffies + msecs_to_jiffies(dev->rep[REP_PERIOD])); } - - spin_unlock_irqrestore(&dev->event_lock, flags); } /** @@ -2373,10 +2312,10 @@ static int input_device_tune_vals(struct input_dev *dev) if (!vals) return -ENOMEM; - spin_lock_irq(&dev->event_lock); - dev->max_vals = max_vals; - swap(dev->vals, vals); - spin_unlock_irq(&dev->event_lock); + scoped_guard(spinlock_irq, &dev->event_lock) { + dev->max_vals = max_vals; + swap(dev->vals, vals); + } /* Because of swap() above, this frees the old vals memory */ kfree(vals); @@ -2468,18 +2407,15 @@ int input_register_device(struct input_dev *dev) path ? path : "N/A"); kfree(path); - error = mutex_lock_interruptible(&input_mutex); - if (error) - goto err_device_del; + error = -EINTR; + scoped_cond_guard(mutex_intr, goto err_device_del, &input_mutex) { + list_add_tail(&dev->node, &input_dev_list); - list_add_tail(&dev->node, &input_dev_list); + list_for_each_entry(handler, &input_handler_list, node) + input_attach_handler(dev, handler); - list_for_each_entry(handler, &input_handler_list, node) - input_attach_handler(dev, handler); - - input_wakeup_procfs_readers(); - - mutex_unlock(&input_mutex); + input_wakeup_procfs_readers(); + } if (dev->devres_managed) { dev_dbg(dev->dev.parent, "%s: registering %s with devres.\n", @@ -2559,20 +2495,17 @@ int input_register_handler(struct input_handler *handler) if (error) return error; - INIT_LIST_HEAD(&handler->h_list); + scoped_cond_guard(mutex_intr, return -EINTR, &input_mutex) { + INIT_LIST_HEAD(&handler->h_list); - error = mutex_lock_interruptible(&input_mutex); - if (error) - return error; - - list_add_tail(&handler->node, &input_handler_list); + list_add_tail(&handler->node, &input_handler_list); - list_for_each_entry(dev, &input_dev_list, node) - input_attach_handler(dev, handler); + list_for_each_entry(dev, &input_dev_list, node) + input_attach_handler(dev, handler); - input_wakeup_procfs_readers(); + input_wakeup_procfs_readers(); + } - mutex_unlock(&input_mutex); return 0; } EXPORT_SYMBOL(input_register_handler); @@ -2588,7 +2521,7 @@ void input_unregister_handler(struct input_handler *handler) { struct input_handle *handle, *next; - mutex_lock(&input_mutex); + guard(mutex)(&input_mutex); list_for_each_entry_safe(handle, next, &handler->h_list, h_node) handler->disconnect(handle); @@ -2597,8 +2530,6 @@ void input_unregister_handler(struct input_handler *handler) list_del_init(&handler->node); input_wakeup_procfs_readers(); - - mutex_unlock(&input_mutex); } EXPORT_SYMBOL(input_unregister_handler); @@ -2618,19 +2549,17 @@ int input_handler_for_each_handle(struct input_handler *handler, void *data, int (*fn)(struct input_handle *, void *)) { struct input_handle *handle; - int retval = 0; + int retval; - rcu_read_lock(); + guard(rcu)(); list_for_each_entry_rcu(handle, &handler->h_list, h_node) { retval = fn(handle, data); if (retval) - break; + return retval; } - rcu_read_unlock(); - - return retval; + return 0; } EXPORT_SYMBOL(input_handler_for_each_handle); @@ -2718,27 +2647,22 @@ int input_register_handle(struct input_handle *handle) { struct input_handler *handler = handle->handler; struct input_dev *dev = handle->dev; - int error; input_handle_setup_event_handler(handle); /* * We take dev->mutex here to prevent race with * input_release_device(). */ - error = mutex_lock_interruptible(&dev->mutex); - if (error) - return error; - - /* - * Filters go to the head of the list, normal handlers - * to the tail. - */ - if (handler->filter) - list_add_rcu(&handle->d_node, &dev->h_list); - else - list_add_tail_rcu(&handle->d_node, &dev->h_list); - - mutex_unlock(&dev->mutex); + scoped_cond_guard(mutex_intr, return -EINTR, &dev->mutex) { + /* + * Filters go to the head of the list, normal handlers + * to the tail. + */ + if (handler->filter) + list_add_rcu(&handle->d_node, &dev->h_list); + else + list_add_tail_rcu(&handle->d_node, &dev->h_list); + } /* * Since we are supposed to be called from ->connect() @@ -2774,9 +2698,8 @@ void input_unregister_handle(struct input_handle *handle) /* * Take dev->mutex to prevent race with input_release_device(). */ - mutex_lock(&dev->mutex); - list_del_rcu(&handle->d_node); - mutex_unlock(&dev->mutex); + scoped_guard(mutex, &dev->mutex) + list_del_rcu(&handle->d_node); synchronize_rcu(); }