From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 159A91E0DF5 for ; Mon, 20 Jan 2025 15:15:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737386125; cv=none; b=Az9+SFmb5JJVOdawTiJNwScFoedHBbBVZEKSy9UIR9XcJh6+TAt0IWbQlIcy0Sdc6Aefl9YYQOfJRE08nm+LZe9G2hhaVV+jaUdnwhwzRM+kWb2mT78z0K16c9QTuK5pJAfY/rBMQoeREmYf8bSbZ+vsDK0oLxzaM6Vlf5y9Dgs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737386125; c=relaxed/simple; bh=pdfD+WMJzLpldEAxMBN+beptAi+MOuTFE9aVXXo20RY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dfE0sv3jCvQSIkBEWt8D7ZUktYSUSfd62UrcwMyzCm8XBBSKBt6hx8zMtz5XABQ1wP/NR5NFBqwvzFq2d1vky2QxDWo27H+W0sz5zxV95KgiNJOug6ZKJwFRUzAgCg91+8BZauCnPI84P4SwN0cCL6SDuYTaeflFVj9jLC34YRo= 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=D19Wd/5u; arc=none smtp.client-ip=209.85.128.52 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="D19Wd/5u" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-43690d4605dso31227675e9.0 for ; Mon, 20 Jan 2025 07:15:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737386121; x=1737990921; 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=jCi2OnTM5qC2jJdB+QtoqWue7Uopuli4sTbtNpaftoE=; b=D19Wd/5u2bakTfoCW7TBeEFkfSSDSsQyJObMWRTI4ELAZY1i6MO7NSuBa9URyz5hFn wfVpdtBb4WbF56OEAk6/yubbsK6V8HwIP3ndEHYyShoTu61tIHdPfAiDHLaiu6eT4/qG rnhz451YtGjTEeXgtsYgg3b79HVjq/E7xulJIRA1dWiw/2c+FgfwF04pJojGE8Tx2tkT NjXO5sD/aIcNYgJ2vdrwfO3vvyabdlOzUeBg18uHyaezt+vjDPOLknAUAWS76z0FidMX HoTLWdYDwtLfLEhZEzd9z6xC5PPjL1lVD/Os+a1E8Nqw+x3qjI54bk/aUvAvkqD7vkZg K8rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737386121; x=1737990921; 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=jCi2OnTM5qC2jJdB+QtoqWue7Uopuli4sTbtNpaftoE=; b=wMhyDensDVim23ibX9wy8P+YuQLb9QmmS+vVDcUh7HW3SsfBZhkU81pbrKiXaA/8uR 1hn9qlxIStB/cTE8vJB6wTPZ3K6kMX8gYGspEO5RbiHY5/gK/s8BacR9orAk0z1cdQz1 ztrem2U+sBIZu7nkJLCMqbonHu0G52iSxyePdtcW4j+v73QDOGLNabfIi7NeJXvVUzVp Rxf5Rz5tU4Ycp/83RahUPccbkXxH5XAlEiibZUEbV99ToULPDXx0VBOpfBmTya00hb3a 4mzDvteBm/gj7ttKHuIJTx7LQswp9uQZM5/G8RTEPIYoyLCc/uKE24QS+QwWTaqHc/g2 +OgA== X-Forwarded-Encrypted: i=1; AJvYcCX/zATeuuSCnNGUCSewjl3otqSaFj5SBCSy4wUd9HA3BlwRTMYya0GajDM/86hWWgGQeafs+RB2E1jdsdI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzm2cTnV+PqHugUKInkiF7E5deL1c38dLFfq1KQgYeLvgOvespw KzApqQZ38AIy9tbW01g/ybvhAuCKbx1+0+7oS4ucPbYfmdQhGEbQ X-Gm-Gg: ASbGncsTxa8CoYQ1AvoXb7dfeXziC8lorFOV+qfCnvIH34Wv5Zg0/N1e+Wh6KXgHWVG z1u2uTgdhTW3IHhiVBYccYaC+AK+5HCYn2MFidjvWNzFHoDnGssna04D4w4S1zlB7OG+7xebyPn d1wkEUVlwW8hxQjDgGNkAyQ1Df/2rPIz/TtvhNK47snE3j44guUvDwubQeqetU50CSTHK/f1vSu ddTllfz6WkdgXWu3KEGbQl7EGxfySs/FaG3uw3KpYHI4NT2xETswxB00d5eMEknqoE/971LXMQC U3G19hFz1g== X-Google-Smtp-Source: AGHT+IG1DgjFv6bPcJnBgOMYqLB0iv+3Hhda6aDLo4vOr3ZL1xBdy3Zx2Qxb+B6dlbJou6UJjxFWCw== X-Received: by 2002:a05:600c:4ec8:b0:434:f219:6b28 with SMTP id 5b1f17b1804b1-43891435c37mr113466355e9.24.1737386121121; Mon, 20 Jan 2025 07:15:21 -0800 (PST) Received: from egonzo (82-64-73-52.subs.proxad.net. [82.64.73.52]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c74995f6sm206237005e9.1.2025.01.20.07.15.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 07:15:20 -0800 (PST) Date: Mon, 20 Jan 2025 16:15:18 +0100 From: Dave Penkler To: Dan Carpenter 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: References: <20250118145046.12181-1-dpenkler@gmail.com> <20250118145046.12181-3-dpenkler@gmail.com> <3a31262b-6bed-4f74-b00e-a124a9486e07@stanley.mountain> 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: <3a31262b-6bed-4f74-b00e-a124a9486e07@stanley.mountain> On Mon, Jan 20, 2025 at 10:15:55AM +0300, Dan Carpenter wrote: > 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. Hi, I fully agree with you and this is the direction we are pursuing in the gpib driver code base. We have very long way to go still and I apologize for not splitting up the changes into multiple patches. Thanks for the pointer to git citool. -dave > > regards, > dan carpenter >