From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 879121F0E32 for ; Sat, 21 Dec 2024 11:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734780579; cv=none; b=u7ohQ4i0NERgpFtYGWBS4YASJFCMdDubpPqG5zXutwKtcRT7IgB3LpjUkaZvI42vvzPQ2uv3+QW1aCcITKLexWZSWndQEWK1p51P2LPLt0YQZZfkbJFDx/wb5rghWWnHTMfuTaEUNT7NfIFS9a27qkruemZlUugJUTEj73Om4so= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734780579; c=relaxed/simple; bh=M95Q45a+S4okLrPxtCToZN78qSZJ4gLS3N5midkMDuo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gBrwtkxxo139zgJwAkgGDFXVv/rlT2XsTuZWvLyHSyrnZMMpXehRtmRLkQIZEoTOgkZgAFB7SxCmxjHs+5w1g5WhVsehal8RFM2GIH9ofjG12lD7mBAFEZTcAZjYo8LnTL5PMIiNtkK+fbZMedcYKi4mWdHrFqwoAAjfOdr4has= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nTMC5tza; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nTMC5tza" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7feffc649efso348219a12.0 for ; Sat, 21 Dec 2024 03:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734780577; x=1735385377; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=PmtXehoW7x3so4SbUDnv5CcTQyXH+DZ9Sj8N214cQ0I=; b=nTMC5tzakY/tJpwxZ1VyLGZj+4f7PP+J3dPJvFzi8MA3Q6/a8LH/lEy/5QaQ6N1mKQ Zxs4On1FoVPk4JDu4ywAj7fOafAfpYkoRpSg2Tjh83xRj7LU1UO3lTptsnwL7UVFR8uO /8Uo5Sy3hmBbejrWDynKWgjC2LBFaCNxVP05sl/wnAwy/Rdf0OKDDoMxZrlW/VcQpoAZ LQpqg0TdripK7BSfBBc1imCzaoRQnnd4LEZUTqqeqwj1hloW/Y/h3Y0lDMBOBF3yJTF6 C7cRmRwKfSGIYOyHZoqATPcxhCJhvZ+uSfCg9cf/vVDe8XSLcHWg2tnd0ECkxge8T4+B IoPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734780577; x=1735385377; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PmtXehoW7x3so4SbUDnv5CcTQyXH+DZ9Sj8N214cQ0I=; b=O8TBAUX2J3Qec8Fqv4V+yRjxXhVaWuf7VTZ9bvb+vNURIo0VG+WsVNizdmHoek+Yel CejQuFsi2NICzwN8CZQspaYf/Pbwyo4Y7kL0U/qEox0D9qsPXwNvuv7H/Z46hnm6oMUB KPBQ3T7lTnYPh1CGk0L5IDNBOnBcfFddKwkeIgNMQI9CHLVYEY4j1+zUr7AnVJfEnmK7 P4L6mpGIA+WIq3QIKS9155sfa9uPAWALcmdnqeOcqLasP80q8WrBH/dxtQHfgjN+XgLS p00xg54yoTcW8xS4wMBKAHnTAJgKv5CVtShAOuEvvv2Y2W4UBRFnQ1WQ/7iiRUZjItJ4 uslA== X-Forwarded-Encrypted: i=1; AJvYcCWc2n7UTwijVymO8niyLuVa7WpGkDZKHy8ALQ6vfMhw81Gf/Aygc9mBovYHOls+E+YiwySmckC1ckiJdwE=@vger.kernel.org X-Gm-Message-State: AOJu0YwzBa8QxN3gT86g7E79VOfNvdhqcZWQk0jrJ7DY4nvBpRXCEw90 4tdfuCQOvWPDKD7aSPlyfy5OEt1fvUP9y2QYBVU9O4oMHdB/dlYb X-Gm-Gg: ASbGncsXtetN5jlze0u/1ipo9PWOSoRWWpYtVwTarNd2BPN9bhtA26lQx7gEvEHPU41 9ahENKIifc9m66ybccs9b7T58B49VZAAiaMwZdYe6b7XzvvdNY2aACLA/nis5tes2q0cg3RFjvV 4ZGNR34GgHbn+qHrOf0oV2cVp6BRvROn4X+Y8vCOVJ4lNgFI2xEPhDxjspkka4lKgTWpWEqo50K 8fbujwoq/3Mfpw1LQ8Fyevq5Ta65IFb7dbO/unQUYrWAAASeYKAetjRG+/dc7SLASg= X-Google-Smtp-Source: AGHT+IG7E3coi1smTyxtqjSgAeiEJpTBAtnXuWzlP/BjzfrV4QT6mptTRcC+NmTgKI76pqdEfhjGIg== X-Received: by 2002:a05:6a00:a84:b0:72a:a7a4:aba5 with SMTP id d2e1a72fcca58-72abdd6f923mr3389186b3a.1.1734780576591; Sat, 21 Dec 2024 03:29:36 -0800 (PST) Received: from [192.168.1.19] ([171.76.86.134]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad90c182sm4746276b3a.189.2024.12.21.03.29.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 Dec 2024 03:29:36 -0800 (PST) Message-ID: Date: Sat, 21 Dec 2024 16:59:31 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] staging: gpib: cb7210: Add error handling To: Greg KH Cc: dpenkler@gmail.com, dan.carpenter@linaro.org, roheetchavan@gmail.com, arnd@arndb.de, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org References: <20241221091121.35476-1-niharchaithanya@gmail.com> <2024122119-unclamped-affecting-0e0a@gregkh> <2024122133-outskirts-causing-099a@gregkh> Content-Language: en-US From: Nihar Chaithanya In-Reply-To: <2024122133-outskirts-causing-099a@gregkh> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 21/12/24 15:13, Greg KH wrote: > On Sat, Dec 21, 2024 at 10:25:41AM +0100, Greg KH wrote: >> On Sat, Dec 21, 2024 at 02:41:25PM +0530, Nihar Chaithanya wrote: >>> The if condition in cb7210_init_module() would always fail as >>> the value of err is constantly 0. The function >>> cb_pcmcia_init_module() can be refactored into a single line, >>> and can be replaced entirely with pcmcia_register_driver(). >>> >>> Replace redundant cb_pcmcia_init_module() with >>> pcmcia_register_driver() which returns appropriate error code if >>> it fails. Handle the error if it fails and print the debug message. >>> >>> This issue was reported by Coverity Scan. >>> Report: >>> CID 1635894: (#1 of 1): 'Constant' variable guards dead code (DEADCODE) >>> dead_error_line: Execution cannot reach this statement: return -1;. >>> >>> Signed-off-by: Nihar Chaithanya >>> --- >>> v1 --> v2: Replaced the redundant cb_pcmcia_init_module() with >>> pcmcia_register_driver(). >>> >>> drivers/staging/gpib/cb7210/cb7210.c | 13 ++++--------- >>> 1 file changed, 4 insertions(+), 9 deletions(-) >>> >>> diff --git a/drivers/staging/gpib/cb7210/cb7210.c b/drivers/staging/gpib/cb7210/cb7210.c >>> index 63df7f3eb3f3..abd6632d8448 100644 >>> --- a/drivers/staging/gpib/cb7210/cb7210.c >>> +++ b/drivers/staging/gpib/cb7210/cb7210.c >>> @@ -1351,12 +1351,6 @@ static struct pcmcia_driver cb_gpib_cs_driver = { >>> .resume = cb_gpib_resume, >>> }; >>> >>> -int cb_pcmcia_init_module(void) >>> -{ >>> - pcmcia_register_driver(&cb_gpib_cs_driver); >>> - return 0; >>> -} >>> - >>> void cb_pcmcia_cleanup_module(void) >>> { >>> DEBUG(0, "cb_gpib_cs: unloading\n"); >>> @@ -1526,11 +1520,12 @@ static int __init cb7210_init_module(void) >>> gpib_register_driver(&cb_pcmcia_interface, THIS_MODULE); >>> gpib_register_driver(&cb_pcmcia_accel_interface, THIS_MODULE); >>> gpib_register_driver(&cb_pcmcia_unaccel_interface, THIS_MODULE); >>> - err += cb_pcmcia_init_module(); >>> + err = pcmcia_register_driver(&cb_gpib_cs_driver); >>> #endif >>> - if (err) >>> + if (err) { >>> + pr_err("cb7210: registering PCMCIA driver with the bus core failed\n"); >>> return -1; >> Not your issue, but "-1" is not a valid error number, shouldn't this be >> returning a real error (i.e. the one that was returned?) >> >> And err += is crazy, thanks for removing that, BUT you forgot to unwind >> the previous functions so now if pcmcia_register_driver() fails, you >> have a semi-registered system and then the module will unload (as init >> fails) and bad things will happen :( So I need be unregistering the driver if the pcmcia_register_driver() fails right? >> So you kind of just made the code worse overall, not better, which >> really isn't a good idea for a "bugfix" that covertity was trying to >> point out. > And (this is taking you down a path that is much larger than you > expected to just fix this one issue, sorry), it looks like > gpib_register_driver() can fail, so it MUST return an error value so you > can properly unwind from it. So that too needs to be fixed up here > (also minor nit, gpib_register_driver() should not be calling pr_info(), > but that's a different issue.) Yes Greg, gpib_register_driver() should be returning -ENOMEM if it fails, thank you for pointing it out, I'll change the gpib code wherever the drivers are registered, I'll send the patch as soon as I can. > In all, there are loads of tiny things like this to fix up in the gpib > code, which is great, have fun! yes, I am happy to contribute. > thanks, > > greg k-h thank you, Nihar