Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3580617pxy; Mon, 26 Apr 2021 05:15:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH6BwmlqSXptO7VLUwB5jSPqe0W5MlG9TuzBCVuePZ6x8nQiGCNsDDa9AKTsprguooF7sB X-Received: by 2002:a17:90a:1f49:: with SMTP id y9mr21970244pjy.69.1619439310046; Mon, 26 Apr 2021 05:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619439310; cv=none; d=google.com; s=arc-20160816; b=UkHoeQD8QCLwgLzRTFIrBHwtBKh54x6tbrVFtzZdCbfL2o6BNsJ92cepLrNLHt9V7u /hpFtHPEn5ENF4URl+ez6hdyoUzxGSC10cSdCZhne+c0Rjepx1WPRFEv2zKa9Q5Hh0rO CbzIPwoaON9IZ9JhrNpZc/IqD0gukFoRFpCXIG/sg+a2RIKSAYSQS7ZXguyEPMtDWs1Z S0yiRg3qUjBX1oT0JrWJ4BczaLCk0y5czTKwPmCvjO7IkPpDiJwYvC5yYWYZoYu+QW9l +N3I4VqWTcAU0ONVSihWHxNiEYqQ+vnJNw1wGdoZN87s3rk9DA4DvBFzM0sSl8WvQQPf 2jxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iDmpw59YgrTqSaXDT0vvOjvpnrD3Lw8TcdGJ0Q4B6lw=; b=tZmTagoNtG8VhtFrhfvpVoDl6yAd8GZH4jtkVAXhqGPywtulXU5+TmsV0rCkN0dQag /nUkEpprwJ2x5mOiMp0oCgHOQenkQnQQVqnEVPUAYyZHjmF17EZatM3kGYPy3JmclwkF uk1CZIZSLSqmIPkGHTo2j+8xAzlX7M9rTWFXWbUBF5k15Q3mh1X5Wkqj3ShWgTQVyMFo JfOAO5nFZLUQlOurUZoQ28a+QcF0Xgep9c7kz2vYEc8pRtMmPCzFaJ4nFAphqf3ThCKj tWeF13M/MKDcLzbcEWxzN+RKrHq9KgJaljm1cMfxgpHJrQl697gq7DXKKz17XRvMGuKn 6Guw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EE4JGHF9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t7si19419691plg.18.2021.04.26.05.14.58; Mon, 26 Apr 2021 05:15:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EE4JGHF9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233262AbhDZMOb (ORCPT + 99 others); Mon, 26 Apr 2021 08:14:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:41792 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231550AbhDZMOa (ORCPT ); Mon, 26 Apr 2021 08:14:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 009BE61178; Mon, 26 Apr 2021 12:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619439229; bh=3jTHsaN6ohRdOgJEHP9SWTgo6GOAMiOIw+coUfFMB6Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EE4JGHF9yusSCOW1/++ZdJIBj33EDn3bHr1UzDxz5uuqO9S1me5qfJrBts4VmQtZb hyPwP53XqKJDoD0mzg52RrBURcZH2OIjU0PhSRb6uK2hIHdc9v65NADPHOAG9GTNLe PAR09iM1oriu09Ybk2+ZCb8iww8MbYWJitb+rzknZSN2yJquRUf3sd2Z4Ska19fkhb RUYyAP5xRYFvPxtRy1nfqy+zQRALtqwCioJ4n/LtRcG6evtFpVkR9lYDFsb4OaMZRW PgVGSoH7kjtegpV3xnQ9Aj5uTThlf3KINgPsmAoJTNi87leEeUIJSlQSYUd99MC5Ki kJS8El89cWo0Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lb07i-0006G9-V9; Mon, 26 Apr 2021 14:13:59 +0200 Date: Mon, 26 Apr 2021 14:13:58 +0200 From: Johan Hovold To: Yang Li Cc: jikos@kernel.org, benjamin.tissoires@redhat.com, linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] HID: hiddev: return -ENOMEM when kmalloc failed Message-ID: References: <1619429726-54768-1-git-send-email-yang.lee@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1619429726-54768-1-git-send-email-yang.lee@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 26, 2021 at 05:35:26PM +0800, Yang Li wrote: > The driver is using -1 instead of the -ENOMEM defined macro to > specify that a buffer allocation failed. Using the correct error > code is more intuitive. > > Smatch tool warning: > drivers/hid/usbhid/hiddev.c:894 hiddev_connect() warn: returning -1 > instead of -ENOMEM is sloppy > > No functional change, just more standardized. > > Reported-by: Abaci Robot > Signed-off-by: Yang Li > --- > drivers/hid/usbhid/hiddev.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c > index 45e0b1c..88020f3 100644 > --- a/drivers/hid/usbhid/hiddev.c > +++ b/drivers/hid/usbhid/hiddev.c > @@ -891,7 +891,7 @@ int hiddev_connect(struct hid_device *hid, unsigned int force) > } > > if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) > - return -1; > + return -ENOMEM; Please try to understand the code that you're changing based on feedback from some tool. All other error paths here return -1 and the return value of this function is only compared to zero. How is changing only one of these paths an improvement in any way? > > init_waitqueue_head(&hiddev->wait); > INIT_LIST_HEAD(&hiddev->list); Johan