Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp829095pxk; Wed, 23 Sep 2020 18:10:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtvMy38tRLQ24nnj2FALHA40itNidbp4pDZJL7DH+21XGcGxRAI6FR9UifVgi4Gzn+P+E+ X-Received: by 2002:a17:906:b156:: with SMTP id bt22mr2196824ejb.481.1600909839095; Wed, 23 Sep 2020 18:10:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600909839; cv=none; d=google.com; s=arc-20160816; b=McNEu44bmAIzhrYD5EdjnrnmkygEHgtGN/AaWRQxwt4pwcOtCeqpzGUhk9mFZOVeDo F9EEm2mjcpYdi7Z3EVLgI+/zZyy4jRV9juAS04oZVcBIX9qivrmfIVx4wQeWtGEuGzau R1SUdi6zyorLTviS2qTLcJld6UxYyNEXKu4VfzAldoU+KAtzUIzVYLCPSAGft0FRtfh+ n5GPGc2dWT829JvqxBbY3r/KrU6Jpkd0WAEIdekbCOnA6hh5LO1lpEk206iGQldAhBLd qGVo6Q/oEJP9N/90BXWH5Zdy2YwVP8yf2GwovGjTljcVojr+Wv3OFowH1tWV/md3crTY ugOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date; bh=uFbN4L2CqZGf7XMKKXjCmG7sq5SJLvK+jzwtsTy8mSQ=; b=PUVr30Hfb3mMHilqwQwH3lvm6fcVcLGk14B7VqhZ+6bdA2KpZLXUB6GCQ5N+clRkfG VwxUkTuPkGcGHpZsmFYkkLkOvsMOODRVdFg42wPyorD66PyUYHOxIcKUlPn2kwe4AEIn jWIbrgBjzb2N/XQVMBnvkOSwwYnbZBzNP5sJPtcmpczhWO/AteUEZsgYMLBfd+Ter55Q cIO+UjeE+9MTUy/Orc1Mlc/0FrRm88zpyPyfAUK4WV3dy2jWaE4BMtbGmSXKRFzpC+SV iilqtqB2uv2eHOKxEkHUo3EbF26YJQL2lxUMvg9bpyXMfgjnRckCdir2/7l4CbP9KVte cVwg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w17si1068734eds.432.2020.09.23.18.10.15; Wed, 23 Sep 2020 18:10:39 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbgIXBHP (ORCPT + 99 others); Wed, 23 Sep 2020 21:07:15 -0400 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:46644 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbgIXBHO (ORCPT ); Wed, 23 Sep 2020 21:07:14 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by kvm5.telegraphics.com.au (Postfix) with ESMTP id 153AA2A45B; Wed, 23 Sep 2020 21:07:11 -0400 (EDT) Date: Thu, 24 Sep 2020 11:07:14 +1000 (AEST) From: Finn Thain To: Geert Uytterhoeven cc: "David S. Miller" , Bartlomiej Zolnierkiewicz , Joshua Thompson , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org Subject: Re: [PATCH v2] ide/macide: Convert Mac IDE driver to platform driver In-Reply-To: Message-ID: References: <3cf40b9df80a99a3eee6d3af79437016038f0a44.1600051331.git.fthain@telegraphics.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert, On Wed, 16 Sep 2020, Finn Thain wrote: > On Tue, 15 Sep 2020, Geert Uytterhoeven wrote: > > > > > > --- a/drivers/ide/macide.c > > > > > +++ b/drivers/ide/macide.c > > > > > > > > > @@ -109,42 +110,61 @@ static const char *mac_ide_name[] = > > > > > * Probe for a Macintosh IDE interface > > > > > */ > > > > > > > > > > -static int __init macide_init(void) > > > > > +static int mac_ide_probe(struct platform_device *pdev) > > > > > { > > > > > > > > > printk(KERN_INFO "ide: Macintosh %s IDE controller\n", > > > > > mac_ide_name[macintosh_config->ide_type - 1]); > > > > > > > > > > - macide_setup_ports(&hw, base, irq); > > > > > + macide_setup_ports(&hw, mem->start, irq->start); > > > > > > > > > > - return ide_host_add(&d, hws, 1, NULL); > > > > > + rc = ide_host_add(&d, hws, 1, &host); > > > > > + if (rc) > > > > > + return rc; > > > > > + > > > > > + platform_set_drvdata(pdev, host); > > > > > > > > Move one up, to play it safe? > > > > > > > > > > You mean, before calling ide_host_add? The 'host' pointer is > > > uninitialized prior to that call. > > > > Oh right, so the IDE subsystem doesn't let you use the drvdata inside > > your driver (besides in remove()) in a safe way :-( > > > > The IDE subsystem does allow other patterns here. I could have changed > ide_host_alloc() into ide_host_register() followed by ide_host_add() but > I could not see any benefit from that change. > Sorry, I meant to say, "I could have changed ide_host_add() into ide_host_alloc() followed by ide_host_register() ..." > A quick search for "platform_device" shows that the driver does not use > any uninitialized driver_data pointer (because ide_ifr is a global). In > your message of September 9th you readily reached the same conclusion > when you reviewed v1. > > If mac_ide_probe() followed the usual pattern it might make review > easier (as reviewers may not wish to consider the entire driver) but > does that really make the code more "safe"? > I still think that "if it ain't broke, don't fix it" is actually the "safe" option for macide.c. But I'm happy to make additional changes, test them and send v5 if that's preferred. Looking further at the drivers using ide_host_register(), I see that falconide.c is missing a set_drvdata() call, while tx4939ide.c calls set_drvdata() after ide_host_register(). The latter example is not a bug. The pattern I used, that is, calling set_drvdata() after ide_host_add(), is actually more popular among IDE drivers than the pattern you suggested, that is, set_drvdata() followed by ide_host_register(). Either way, I don't see any bugs besides the one in falconide.c. Regarding falconide.c, my inclination is to send a fix following the more common pattern (among IDE drivers), as below. I guess that may prompt the subsystem maintainers to make known their views on the style question. diff --git a/drivers/ide/falconide.c b/drivers/ide/falconide.c index dbeb2605e5f6e..607c44bc50f1b 100644 --- a/drivers/ide/falconide.c +++ b/drivers/ide/falconide.c @@ -166,6 +166,7 @@ static int __init falconide_init(struct platform_device *pdev) if (rc) goto err_free; + platform_set_drvdata(pdev, host); return 0; err_free: ide_host_free(host); @@ -176,7 +177,7 @@ static int __init falconide_init(struct platform_device *pdev) static int falconide_remove(struct platform_device *pdev) { - struct ide_host *host = dev_get_drvdata(&pdev->dev); + struct ide_host *host = platform_get_drvdata(pdev); ide_host_remove(host);