From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752265AbcAEQy4 (ORCPT ); Tue, 5 Jan 2016 11:54:56 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35171 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbcAEQyp (ORCPT ); Tue, 5 Jan 2016 11:54:45 -0500 From: Peter Senna Tschudin To: thomas@winischhofer.net, gregkh@linuxfoundation.org, trivial@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Peter Senna Tschudin , Peter Senna Tschudin Subject: [PATCH 4/5] usb-misc: sisusbvga: Remove kmalloc logs and fix error path Date: Tue, 5 Jan 2016 17:54:09 +0100 Message-Id: <1452012850-6990-5-git-send-email-peter.senna@collabora.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452012850-6990-1-git-send-email-peter.senna@collabora.com> References: <1452012850-6990-1-git-send-email-peter.senna@collabora.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Senna Tschudin This patch remove four calls to dev_err() from sisusb_probe() as reporting memory allocation failures is redundant: - Remove a call to dev_err() that was reporting unsuccesful call to kzalloc(). - Remove two calls to dev_err() that were reporting unsuccesful calls to kmalloc(). - Remove a call to dev_err() that was reporting unsuccesful call to kmalloc(), and replace it by code that clean up previously allocated resources and abort the probe with -ENOMEM. Before this modification sisusb->SiS_Pr could be dereferenced even it was null. Signed-off-by: Peter Senna Tschudin --- Tested by compilation only. drivers/usb/misc/sisusbvga/sisusb.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c index 6cce4fb..875e365 100644 --- a/drivers/usb/misc/sisusbvga/sisusb.c +++ b/drivers/usb/misc/sisusbvga/sisusb.c @@ -3040,10 +3040,9 @@ static int sisusb_probe(struct usb_interface *intf, /* Allocate memory for our private */ sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL); - if (!sisusb) { - dev_err(&dev->dev, "Failed to allocate memory for private data\n"); + if (!sisusb) return -ENOMEM; - } + kref_init(&sisusb->kref); mutex_init(&(sisusb->lock)); @@ -3070,7 +3069,6 @@ static int sisusb_probe(struct usb_interface *intf, sisusb->ibufsize = SISUSB_IBUF_SIZE; sisusb->ibuf = kmalloc(SISUSB_IBUF_SIZE, GFP_KERNEL); if (!sisusb->ibuf) { - dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for input buffer"); retval = -ENOMEM; goto error_2; } @@ -3081,7 +3079,6 @@ static int sisusb_probe(struct usb_interface *intf, sisusb->obuf[i] = kmalloc(SISUSB_OBUF_SIZE, GFP_KERNEL); if (!sisusb->obuf[i]) { if (i == 0) { - dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for output buffer\n"); retval = -ENOMEM; goto error_3; } @@ -3119,7 +3116,8 @@ static int sisusb_probe(struct usb_interface *intf, /* Allocate our SiS_Pr */ sisusb->SiS_Pr = kmalloc(sizeof(struct SiS_Private), GFP_KERNEL); if (!sisusb->SiS_Pr) { - dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate SiS_Pr\n"); + retval = -ENOMEM; + goto error_4; } #endif -- 2.5.0