From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linus Walleij Subject: Re: [PATCH 1/6] gpio: make the gpiochip a real device Date: Wed, 4 Nov 2015 11:48:47 +0100 Message-ID: References: <1445502750-22672-1-git-send-email-linus.walleij@linaro.org> <1445502750-22672-2-git-send-email-linus.walleij@linaro.org> <20151102103116.GE8676@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from mail-ob0-f174.google.com ([209.85.214.174]:33511 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932467AbbKDKss (ORCPT ); Wed, 4 Nov 2015 05:48:48 -0500 Received: by obbww6 with SMTP id ww6so9903164obb.0 for ; Wed, 04 Nov 2015 02:48:47 -0800 (PST) In-Reply-To: Sender: linux-gpio-owner@vger.kernel.org List-Id: linux-gpio@vger.kernel.org To: Johan Hovold Cc: "linux-gpio@vger.kernel.org" , Alexandre Courbot , Arnd Bergmann , Michael Welling , Markus Pargmann , Mark Brown , Amit Kucheria On Tue, Nov 3, 2015 at 10:24 PM, Linus Walleij wrote: > On Mon, Nov 2, 2015 at 11:31 AM, Johan Hovold wrote: >> On Thu, Oct 22, 2015 at 10:32:25AM +0200, Linus Walleij wrote: > >>> + * We memset the struct to zero to avoid reentrance issues. >>> + */ >>> + memset(&chip->device, 0, sizeof(chip->device)); >> >> This is an indication of a larger problem. >> >> First of all, you must never register the same device structure twice. >> >> And the larger problem is: With the current interface where a struct >> gpio_chip is passed and registered, how would you prevent the device >> from going away while in use? > > OK I see. What about the design pattern elsewhere to pass a > gpiochip desc and have a new gpiochip_register() create the > gpiochip and delete gpiochip_add()? > > That's the usual pattern in subsystems. Thinking about it maybe it's simplest to just make ->dev a pointer and kzalloc() it at gpiochip_add(). That should solve this. Yours, Linus Walleij