All of lore.kernel.org
 help / color / mirror / Atom feed
From: Elias Vanderstuyft <elias.vds@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-api@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Elias Vanderstuyft <elias.vds@gmail.com>
Subject: [PATCH 1/2] Input: Document and check on implicitly defined FF_MAX_EFFECTS
Date: Thu, 17 Sep 2015 19:29:47 +0200	[thread overview]
Message-ID: <1442510988-3164-2-git-send-email-elias.vds@gmail.com> (raw)
In-Reply-To: <1442510988-3164-1-git-send-email-elias.vds@gmail.com>

There is an undocumented upper bound for the total number of ff effects:
    FF_GAIN (= 96).
This can be found as follows:
- user: write(EV_FF, effect_id, iterations)
    calls kernel: ff->playback(effect_id, ...): starts effect "effect_id"
- user: write(EV_FF, FF_GAIN, gain)
    calls kernel: ff->set_gain(gain, ...): sets gain

A collision occurs when effect_id equals FF_GAIN.
According to input_ff_event(),
FF_GAIN is the smallest value where a collision occurs.
Therefore the greatest safe value for effect_id is FF_GAIN - 1,
and thus the total number of effects should never exceed FF_GAIN.

Define FF_MAX_EFFECTS as FF_GAIN and check on this limit in ff-core.

Signed-off-by: Elias Vanderstuyft <elias.vds@gmail.com>
---
 drivers/input/ff-core.c    | 5 +++++
 include/uapi/linux/input.h | 8 ++++++++
 2 files changed, 13 insertions(+)

diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c
index c642082..0bf7008 100644
--- a/drivers/input/ff-core.c
+++ b/drivers/input/ff-core.c
@@ -318,6 +318,11 @@ int input_ff_create(struct input_dev *dev, unsigned int max_effects)
 		return -EINVAL;
 	}
 
+	if (max_effects > FF_MAX_EFFECTS) {
+		dev_err(&dev->dev, "cannot allocate more than FF_MAX_EFFECTS effects\n");
+		return -EINVAL;
+	}
+
 	ff_dev_size = sizeof(struct ff_device) +
 				max_effects * sizeof(struct file *);
 	if (ff_dev_size < max_effects) /* overflow */
diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index 63915a7..42d7933 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -1200,6 +1200,14 @@ struct ff_effect {
 #define FF_GAIN		0x60
 #define FF_AUTOCENTER	0x61
 
+/*
+ * ff->playback(effect_id = FF_GAIN) is the first effect_id to
+ * cause a collision with another ff method, in this case ff->set_gain().
+ * Therefore the greatest safe value for effect_id is FF_GAIN - 1,
+ * and thus the total number of effects should never exceed FF_GAIN.
+ */
+#define FF_MAX_EFFECTS	FF_GAIN
+
 #define FF_MAX		0x7f
 #define FF_CNT		(FF_MAX+1)
 
-- 
1.9.3


  reply	other threads:[~2015-09-17 17:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17 17:29 [PATCH 0/2] Input: Improve handling of ff max_effects Elias Vanderstuyft
2015-09-17 17:29 ` Elias Vanderstuyft
2015-09-17 17:29 ` Elias Vanderstuyft [this message]
2015-10-15  0:52   ` [PATCH 1/2] Input: Document and check on implicitly defined FF_MAX_EFFECTS Dmitry Torokhov
2015-09-17 17:29 ` [PATCH 2/2] Input: uinput: Sanity check on ff_effects_max and EV_FF Elias Vanderstuyft
2015-09-17 17:29   ` Elias Vanderstuyft
2015-10-15  0:52   ` Dmitry Torokhov
2015-11-05 22:34     ` Elias Vanderstuyft
2015-11-05 22:34       ` Elias Vanderstuyft
2015-11-06  1:32       ` Dmitry Torokhov
2015-11-06  1:32         ` Dmitry Torokhov
2015-11-08 17:37   ` [PATCH v2 " Elias Vanderstuyft
2015-12-19  1:50     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442510988-3164-2-git-send-email-elias.vds@gmail.com \
    --to=elias.vds@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.