From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 5E8A214F132 for ; Mon, 20 Jan 2025 07:16:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737357363; cv=none; b=YKQtoPHJbkRuJ62ZiIaN/JsgXa7IpVte2DQVDm9P8PAyLe1Xq+XDNG6Yi/68Be8n85x9Z6UxD43ocszI6I3UsACxOw13Gdk/t/NW0RnKx18VwQUsN2KQlImoaTO7gekXVnzbKCK5Qygu5SlWmp6xDtwhOc5Qmvg2ukk+3fcX5h8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737357363; c=relaxed/simple; bh=dUrTKTQ8k2DVd2fHNKr/UwFGXTE9LkTppiUxU2s52pI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pdtpNufZGwh7ej4vbXkL11b+Oqwa+BoP84ps6Q733uJbRMxrs/186rwomUFmNrfKXgRqe8yaRuc6C4XnPmuoxA4JN0TNH1Ay4Jujqd7Y8w3dV5iTXz/Fr4OhPVRjEqA6kHN8b2LtDlOS21JKXbFZ/cnMi/JhfB9L36vagLLjqpY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Zd4apg7X; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Zd4apg7X" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-43635796b48so25692305e9.0 for ; Sun, 19 Jan 2025 23:15:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1737357358; x=1737962158; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=MA1HgMl8EKMjR7RR7euObrXd/SWSOhY1b7QdaFCBVkU=; b=Zd4apg7XusKJqi/6pVZ6pBeexAJsC6EgSsCPuiA90psHzwCfCfGkYAZI95l342Heoh X/Y75epHK7PqYR6FrBnUtP4420EXlOoznwLfszB4tZR3Vsjq+Yzk6ZzKvxt5R8w+OS6m AnmE3sqAZCRF//lE8dTUafhB+xTRmPeC6CZ5BoR8CsEkWHDnUz1ci9Vlr+X6FSkK2ALZ oygDtfEJ8gZ3loDz08rpjDUKzsuGRg2/HhwBUapzDRpbbwCixQENTb3EHUAg10gwDho4 00Ow4n7nSfFxLmOm+u1CLfdSoEOdUDx9Qgwaukf49nRo8XAH85RTvLQGopond3KtzmZK 006g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737357358; x=1737962158; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MA1HgMl8EKMjR7RR7euObrXd/SWSOhY1b7QdaFCBVkU=; b=iUfiepH9JxYzG9dGcat3BeGENxRpc49tI55LaV6CO5GstJfrAeqEjXYtAtnTIUhVWr RZdOuObz69WC2o01HNydf9zE5pCFjZcqQBk7ltobXCcN1lXgX9d8B9yLEEwHvvHuvQ8O l6Et3FO/tlfSKUP3wdLm/juM44/FQqQvejkCvRFBwo3+KOOfXFCvvRL1ffCq6/624E4u FMd9zLpT1ZpoolGW6yU+dPWfNbR0cqKz96Gkf5lTZaYV68AENlZcfk+1uE1XBQQX2j0H FZL5O6fnYEkgYqqADZ5VT/wY2P3OjvC2qgYNs9H4sq01BiWIk6eRs6zxAf1cLeX+3syl FS5Q== X-Forwarded-Encrypted: i=1; AJvYcCVUNOpSg9QcCuScDM2KIA2fgjouI+74LWv325DM/7pKc8OIMtSv/+W5GVF+3UhFdrRYnanfxuI+eeR6iUA=@vger.kernel.org X-Gm-Message-State: AOJu0YzIUhg+DDbsOpbLCK/Rg2Tf1p/fuOZFGQVwLrXZxHzgmDF1E79N 7p6rSaa3JTYW4NGUa3EqH8pwyGwhR91bE4u9yWjNfVElopqw1f8Pl0IgqaSxRc4= X-Gm-Gg: ASbGncusinpSKgICKHVm32pnYqHR3NmdURJK9UZ6YazxVUPL1oVJ9WV+JziYB2+qTpk KXrqdkNFemWQCficSJLcBee67sb+hgJTzNQh6EXtfEdWhP5n1+klNx1SU8xO3BdOANcfY0eqS9X HQ6KAi9uIZL/bYXpYDJo2Mm9UGNBhd0iBOx7vBSOEz4c2XCMpLHXfvYELpbrKpGKKofLdO2P/wH TiboFAX/1uoCn3dfwNi32J8o1rLEdUUE68fY3LFh8eW0lHQU+Y4bnAq+dkny1JxWPyk7ed0OOE= X-Google-Smtp-Source: AGHT+IERRIZCKiArrcq0oJ6aPPKBpbgYo3daA/k+bR56VTNm6OLwXRxjcuqW8bkAXiQf7JhMN2gURA== X-Received: by 2002:a05:600c:26c6:b0:436:1af3:5b13 with SMTP id 5b1f17b1804b1-437c6b475f9mr184360455e9.15.1737357358613; Sun, 19 Jan 2025 23:15:58 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438904086cfsm129133155e9.4.2025.01.19.23.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jan 2025 23:15:58 -0800 (PST) Date: Mon, 20 Jan 2025 10:15:55 +0300 From: Dan Carpenter To: Dave Penkler Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] staging: gpib: Agilent usb code cleanup Message-ID: <3a31262b-6bed-4f74-b00e-a124a9486e07@stanley.mountain> References: <20250118145046.12181-1-dpenkler@gmail.com> <20250118145046.12181-3-dpenkler@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250118145046.12181-3-dpenkler@gmail.com> This patch does too many things... It should be split up. People complain about this requirement a lot, but eventually it will become instinctive. I use `git citool` so I can highlight and click to add lines to a commit. In this code there were some dev_info() changes mixed into the unwind code in ->attach() that were hard to separate out into their own commit but it wasn't too complicated. On Sat, Jan 18, 2025 at 03:50:46PM +0100, Dave Penkler wrote: > Remove useless #ifdef RESET_USB_CONFIG code. > patch 1. > Change kalloc / memset to kzalloc > patch 2. > The attach function was not freeing the private data on error > returns. Separate the releasing of urbs and private data and > add a common error exit for attach failure. > > Set the board private data pointer to NULL after freeing > the private data. By setting the private data, this patch actually does fix the double free that I mentioned earlier. It changes the ->detach into a no-op if ->attach fails. Needs a Fixes tag. ;) But I still hope my blog will convince you that the error handling can be re-written in a better way. It shouldn't matter if ->private_data is NULL or non-NULL because the caller should only have to handle success or failure. The caller shouldn't have to handle a dozen different failure modes: 1) Failure but the ->private_data is NULL 2) Failure but the foo->frob pointer is an error pointer 3) Failure but the foo->frob pointer needs to be freed. 4) Failure but the foo->frob pointer contains other pointers which need to be freed. 5) ... It should just be 1) Success: Everything is allocated 2) Failure: Everything is cleaned up and any accesses are probably a use after free. > > Reduce console spam by emitting only one attach message. > > Change last pr_err in attach to dev_err > These last two can probably be combined into one patch? > @@ -1388,11 +1367,19 @@ static int agilent_82357a_attach(gpib_board_t *board, const gpib_board_config_t > retval = agilent_82357a_init(board); > > if (retval < 0) { > - mutex_unlock(&agilent_82357a_hotplug_lock); > - return retval; > + agilent_82357a_cleanup_urbs(a_priv); > + agilent_82357a_release_urbs(a_priv); > + goto attach_fail; > } In my blog talk about how every allocation function should have a matching free() function. These two functions match agilent_82357a_setup_urbs() so we should have a single function to release the urbs. regards, dan carpenter