From patchwork Tue Oct 24 19:00:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10025403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01EDE601E8 for ; Tue, 24 Oct 2017 19:00:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF1BF289F0 for ; Tue, 24 Oct 2017 19:00:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3BA8289F6; Tue, 24 Oct 2017 19:00:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95154289F0 for ; Tue, 24 Oct 2017 19:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751750AbdJXTAW (ORCPT ); Tue, 24 Oct 2017 15:00:22 -0400 Received: from mout.web.de ([212.227.17.12]:57680 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751559AbdJXTAV (ORCPT ); Tue, 24 Oct 2017 15:00:21 -0400 Received: from [192.168.1.2] ([92.227.117.134]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MMVpy-1e7cvL0hxe-008KeT; Tue, 24 Oct 2017 21:00:13 +0200 To: linux-input@vger.kernel.org, Benjamin Tissoires , Jiri Kosina Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] HID: hidraw: Improve a size determination in two functions Message-ID: <0bb90455-4c2b-bf44-1e9e-9542bb223163@users.sourceforge.net> Date: Tue, 24 Oct 2017 21:00:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:fvmASMDHJN2bwjPbD3Gw3S90STs6iEUXTrVkfcHktIWdFfYPgYI RzuGxcNbtlvkUqNp06QsY9KhAyx2DOSJQTb9meDJMx81IeEiV9//J9k24IpyQeTg7Y3/7wY Ow/YlDABkKI8EkZpKnr3XMf6kO3yPYOgFdqkG/uxtQ94RaVG0+pUFSdHbnhYDT3vMeSqn/8 zM8WWe1qv3HNDS375BLbA== X-UI-Out-Filterresults: notjunk:1; V01:K0:SYU/3dAfVaY=:kqFh6fbkoGbJgT0xrF3KyN Q5ydDyCWkmzxFjyW5uJgr3LiOP7qVJ7dQt28m2Nlo821GxKDMFwCMeiDJpXtt3+SLHZWPnt40 yK69TGGFqc6r8n08SJu+/ORnySliVzjF/sJ2gcniopezhWz9lOaxhnhBf7cBQuHWxzFxf7tVq HEIDMb42SoaZbg9o45GeUW5sJDEoXwfD8SXP7w0IFIVgDgtPDP2qqiTDAouK/2ztzGcWMzEbg khuLL0/vD6WbugsvznunwtSQ07CJ4zSXP84VVl7LYECDqIAjjbKfQ5GNtLDmf+U6vgonVELYM r6RtMOak5GQOfBjkPY+B/0r9EScYLLzKX0JyrXS17qfXZ7qprYTYFYen/W0A89AhC7EEdJxep 1UWkWMjLk71waxy/llI5jYTEf7D6ApLGr9PMcPiryPLjS/FZOB0DkNsmpgnJqcbZBY0NT/Z8b v6QHoQH/qLCbOh8iJ7W+WeGFaB05X71unRqpemS6qWW6t6USlb4w1vFJn7ds3Kwd8zI74mFvy +BQREmLtmPT8524ygVcY2Y7db4KfZhtVfniv3xYX847vZLy10aTTQC3fzoqJbC7jFaZq3gXrF 8FWoHmzXL6+ksGRq93pr3Jcd/i+mV0MMobhZxn0a9lEQ5xlfpTurOMntfujc4N34Li4BHWB58 0TsS0igK/9HOKc7ChZkgVJmRXeVPQ3Ak2uCmW8tkCgBJAT/6+oGEWDng/gWOv87HsN4BkIVd0 jRt4E7UqGMDksn9Hvl8BdpVeoFZmhUAOCR3l3qLa6PQtTIw5cKkp17UKOMquCtW1f0EtmxfMb z5tpPRCQqAMnqc9Sr2qUtgM+hoV7IbjmfPN4w9kpMd5WLqlqss= Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Tue, 24 Oct 2017 20:52:19 +0200 * Replace the specification of data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention. This issue was detected by using the Coccinelle software. * Return directly after a call of the function "kzalloc" failed at the beginning of the function "hidraw_open". * Delete the jump target "out" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring Reviewed-by: Benjamin Tissoires --- drivers/hid/hidraw.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 5fbe0f81ab2e..26fbf9e82f84 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -269,10 +269,9 @@ static int hidraw_open(struct inode *inode, struct file *file) unsigned long flags; int err = 0; - if (!(list = kzalloc(sizeof(struct hidraw_list), GFP_KERNEL))) { - err = -ENOMEM; - goto out; - } + list = kzalloc(sizeof(*list), GFP_KERNEL); + if (!list) + return -ENOMEM; mutex_lock(&minors_lock); if (!hidraw_table[minor] || !hidraw_table[minor]->exist) { @@ -304,7 +303,6 @@ static int hidraw_open(struct inode *inode, struct file *file) file->private_data = list; out_unlock: mutex_unlock(&minors_lock); -out: if (err < 0) kfree(list); return err; @@ -513,7 +511,7 @@ int hidraw_connect(struct hid_device *hid) /* we accept any HID device, all applications */ - dev = kzalloc(sizeof(struct hidraw), GFP_KERNEL); + dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) return -ENOMEM;