From patchwork Thu Sep 17 17:29:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias Vanderstuyft X-Patchwork-Id: 7209311 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 56E8BBEEC1 for ; Thu, 17 Sep 2015 17:32:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F1DD20768 for ; Thu, 17 Sep 2015 17:32:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 789922074B for ; Thu, 17 Sep 2015 17:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752530AbbIQRbq (ORCPT ); Thu, 17 Sep 2015 13:31:46 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:37791 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751840AbbIQRaZ (ORCPT ); Thu, 17 Sep 2015 13:30:25 -0400 Received: by wicfx3 with SMTP id fx3so578123wic.0; Thu, 17 Sep 2015 10:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7VrRCWGJVMcWMFcHAmJdlc1T8T2eZPK/deKs1PBzov8=; b=IIW4AC3ENoKidRcay0ELydzIAm12UbLy3CdSwEdB1fByIR7/JUeCIgFvTNLvx9I4Jv ykHUk2gpSZanVOToIFJnYb3t8q+6W2FIVUgIq6rK1vF8R97XLMc+vIYPx/bELVo4H7Yh OhmTa/rDUQ+KZ01O9gmh3Xl124UGw75Gv4Dcety22B/DUe3FnZoFz/e+x9PD//oxWnkT uxOloT9pcgj0yA1yBDF79YE1h0sxNOGEfNTezl/S/Ha6cgalr8EdpO0N1CVKRLZJ/M+U 4hiRbgUN2xeVHIhX9dujVGryUn0SH3+4IraoxjKEU2qHUhzoJNAaOR8g6FM0E8HkkVRW sDfQ== X-Received: by 10.194.52.6 with SMTP id p6mr518164wjo.119.1442511023676; Thu, 17 Sep 2015 10:30:23 -0700 (PDT) Received: from localhost.localdomain (d8D877437.access.telenet.be. [141.135.116.55]) by smtp.googlemail.com with ESMTPSA id uo6sm4515020wjc.1.2015.09.17.10.30.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 10:30:23 -0700 (PDT) From: Elias Vanderstuyft To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Elias Vanderstuyft Subject: [PATCH 1/2] Input: Document and check on implicitly defined FF_MAX_EFFECTS Date: Thu, 17 Sep 2015 19:29:47 +0200 Message-Id: <1442510988-3164-2-git-send-email-elias.vds@gmail.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1442510988-3164-1-git-send-email-elias.vds@gmail.com> References: <1442510988-3164-1-git-send-email-elias.vds@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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)