From patchwork Sun Apr 17 20:46:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 8863551 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 4ECC5BF29F for ; Sun, 17 Apr 2016 20:52:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 35875201C0 for ; Sun, 17 Apr 2016 20:52:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A7D72011D for ; Sun, 17 Apr 2016 20:52:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750803AbcDQUwB (ORCPT ); Sun, 17 Apr 2016 16:52:01 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36517 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750733AbcDQUwB (ORCPT ); Sun, 17 Apr 2016 16:52:01 -0400 Received: by mail-wm0-f66.google.com with SMTP id l6so19700983wml.3 for ; Sun, 17 Apr 2016 13:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=j+xSvAXiQFt2MWOqYmsBS7HJOgvXwU/gYs/qpcsKkhI=; b=05Cn+hI9W/WX/ficsugVHLe6QRNGltDQ0OArwGG7mFF261jADxHWsXKwi9s5Kt4amA wF3spwnD0n46C681wYLZm93uhkk+C/6ThC8MDA/HiJja0HK4YyLF72mVUuyE/Of6J8pc GbNX3EAUrzCU3BaLDkO5I1gveUT6Jw+XWbtZ4Af4Lnqkrk3bQGmtK2fgFyY+vz/T8RhO zeSpG6MdN8oIcS4aBms8ghYbYPnmxrhxkEwBUVBZKtaV9lblYl2srtbhk+ssEmyes9Yz 0z5rhMipxTXXSujEUUgiMs4VU8/y9PbfyL4U0tDV3PQqbWydDQ56s7qFICVDv38mfbon OndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=j+xSvAXiQFt2MWOqYmsBS7HJOgvXwU/gYs/qpcsKkhI=; b=VXihmaeyX3WL/Hjd1kBfxiY3w+yM9N5750z+rCFwDzvNTwFl5NKb5s+S2EJS5rCnbl wmSFCzuqC1Yp9/yrj6WROq/+R+/DVuA8494GX2E/78s1JTsG7JwHWJvJTjmXDljtq0ZP thAbdBouHRTZwQgpy7IuBaVvoW4Gfd3xKEiStbPrZxUPqKSn+UqU+RNyTYstGC2+7BCU RleVmy7fPZ+uZYt1/Iukh02wvpmKVrLcE4L1d1DFqx9/e1PQ/8K31wX13CXVmw2vcR3W v1PJqFrg9IBYeG0mCzp4d+y/hyJHQcgbLweM+y1BdSgWGwaI7JQDxeENhyLYnVnnW98i dmTg== X-Gm-Message-State: AOPr4FWviR6dmm0oN0lpvNj+qfzJfHxDpXzaQyo+bn1TK4FSoydsf3wl3gckgoeY2N3YPg== X-Received: by 10.28.177.132 with SMTP id a126mr6064430wmf.86.1460926319579; Sun, 17 Apr 2016 13:51:59 -0700 (PDT) Received: from ?IPv6:2003:62:5f01:4400:40f7:a5a9:2add:ef63? (p200300625F01440040F7A5A92ADDEF63.dip0.t-ipconnect.de. [2003:62:5f01:4400:40f7:a5a9:2add:ef63]) by smtp.googlemail.com with ESMTPSA id 188sm23262291wmk.6.2016.04.17.13.51.58 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 17 Apr 2016 13:51:58 -0700 (PDT) To: Jiri Kosina , Benjamin Tissoires From: Heiner Kallweit Subject: [PATCH 1/2] hid: thingm: factor out duplicated code to thingm_init_led Cc: linux-input@vger.kernel.org Message-ID: <5713F643.80408@gmail.com> Date: Sun, 17 Apr 2016 22:46:59 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Simplify thingm_init_rgb by factoring out duplicated code to thingm_init_led. Signed-off-by: Heiner Kallweit Reviewed-by: Benjamin Tissoires --- drivers/hid/hid-thingm.c | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/drivers/hid/hid-thingm.c b/drivers/hid/hid-thingm.c index 847a497..a90463e 100644 --- a/drivers/hid/hid-thingm.c +++ b/drivers/hid/hid-thingm.c @@ -157,48 +157,35 @@ static int thingm_led_set(struct led_classdev *ldev, return ret; } +static int thingm_init_led(struct thingm_led *led, const char *color_name, + struct thingm_rgb *rgb, int minor) +{ + snprintf(led->name, sizeof(led->name), "thingm%d:%s:led%d", + minor, color_name, rgb->num); + led->ldev.name = led->name; + led->ldev.max_brightness = 255; + led->ldev.brightness_set_blocking = thingm_led_set; + led->rgb = rgb; + return devm_led_classdev_register(&rgb->tdev->hdev->dev, &led->ldev); +} + static int thingm_init_rgb(struct thingm_rgb *rgb) { const int minor = ((struct hidraw *) rgb->tdev->hdev->hidraw)->minor; int err; /* Register the red diode */ - snprintf(rgb->red.name, sizeof(rgb->red.name), - "thingm%d:red:led%d", minor, rgb->num); - rgb->red.ldev.name = rgb->red.name; - rgb->red.ldev.max_brightness = 255; - rgb->red.ldev.brightness_set_blocking = thingm_led_set; - rgb->red.rgb = rgb; - - err = devm_led_classdev_register(&rgb->tdev->hdev->dev, - &rgb->red.ldev); + err = thingm_init_led(&rgb->red, "red", rgb, minor); if (err) return err; /* Register the green diode */ - snprintf(rgb->green.name, sizeof(rgb->green.name), - "thingm%d:green:led%d", minor, rgb->num); - rgb->green.ldev.name = rgb->green.name; - rgb->green.ldev.max_brightness = 255; - rgb->green.ldev.brightness_set_blocking = thingm_led_set; - rgb->green.rgb = rgb; - - err = devm_led_classdev_register(&rgb->tdev->hdev->dev, - &rgb->green.ldev); + err = thingm_init_led(&rgb->green, "green", rgb, minor); if (err) return err; /* Register the blue diode */ - snprintf(rgb->blue.name, sizeof(rgb->blue.name), - "thingm%d:blue:led%d", minor, rgb->num); - rgb->blue.ldev.name = rgb->blue.name; - rgb->blue.ldev.max_brightness = 255; - rgb->blue.ldev.brightness_set_blocking = thingm_led_set; - rgb->blue.rgb = rgb; - - err = devm_led_classdev_register(&rgb->tdev->hdev->dev, - &rgb->blue.ldev); - return err; + return thingm_init_led(&rgb->blue, "blue", rgb, minor); } static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)