public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Raag Jadav <raag.jadav@intel.com>,
	jarkko.nikula@linux.intel.com, mika.westerberg@linux.intel.com,
	lakshmi.sowjanya.d@intel.com, linux-pwm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/5] pwm: dwc: drop redundant error check
Date: Wed, 14 Feb 2024 19:54:58 +0200	[thread overview]
Message-ID: <Zcz-csPY5x29DP7v@smile.fi.intel.com> (raw)
In-Reply-To: <cv6w4n2ptcdehn5n3mipuyfrtemm4rldhiyppazk4uqdn2xx7e@hxg4kldaacxk>

On Wed, Feb 14, 2024 at 06:45:48PM +0100, Uwe Kleine-König wrote:
> On Thu, Feb 08, 2024 at 07:04:33PM +0200, Andy Shevchenko wrote:
> > On Thu, Feb 08, 2024 at 08:46:44AM +0100, Uwe Kleine-König wrote:
> > > On Thu, Feb 08, 2024 at 12:35:25PM +0530, Raag Jadav wrote:
> > > > pcim_iomap_table() fails only if pcim_iomap_regions() fails. No need to
> > > > check for failure if the latter is already successful.
> > > 
> > > Is this really true? pcim_iomap_table() calls devres_alloc_node() which
> > > might fail if the allocation fails. (Yes, I know
> > > https://lwn.net/Articles/627419/, but the rule is still to check for
> > > errors, right?)
> > 
> > We do not add a dead code to the kernel, right?
> > 
> > > What am I missing?
> > 
> > Mysterious ways of the twisted PCI devres code.
> > Read the above commit message again :-)
> > 
> > For your convenience I can elaborate. pcim_iomap_table() calls _first_
> > devres_find() which _will_ succeed if the pcim_iomap_regions() previously
> > succeeded. Does it help to understand how it designed?
> 
> I assume you're saying that after pcim_iomap_regions() succeeded it's
> already known that pcim_iomap_table() succeeds (because the former
> already called the latter).
> 
> I'm still concerned here. I agree that error checking might be skipped
> if it's clear that no error can happen (the device cannot disappear
> between these two calls, can it?), 

It depends. If you call it in some asynchronous callbacks which may be run
after PCI device disappears, then indeed, it's problematic. But you probably
will have much bigger issue at that point already.

In ->probe() it's guaranteed to work as I suggested (assuming properly working
hardware).

> but for me as an uninitiated pci code
> reader, I wonder about
> 
> 	dwc->base = pcim_iomap_table(pci)[0];
> 
> without error checking. (OTOH, if pcim_iomap_table() returned NULL, the
> "[0]" part is already problematic.)

Seems it's your problem, many drivers use the way I suggested.

> I'd like to have a code comment here saying that pcim_iomap_table()
> won't return NULL.

Why? It's redundant. If you use it, you should know this API.
So, the bottom line, does this API needs better documentation?

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2024-02-14 17:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08  7:05 [PATCH v2 0/5] DesignWare PWM improvements Raag Jadav
2024-02-08  7:05 ` [PATCH v2 1/5] pwm: dwc: drop redundant error check Raag Jadav
2024-02-08  7:46   ` Uwe Kleine-König
2024-02-08 17:04     ` Andy Shevchenko
2024-02-08 17:06       ` Andy Shevchenko
2024-02-14 17:45       ` Uwe Kleine-König
2024-02-14 17:54         ` Andy Shevchenko [this message]
2024-02-15  9:22           ` Uwe Kleine-König
2024-02-15 13:36             ` Andy Shevchenko
2024-02-15 17:20               ` Uwe Kleine-König
2024-02-15 19:25                 ` Andy Shevchenko
2024-02-08  7:05 ` [PATCH v2 2/5] pwm: dwc: Add 16 channel support for Intel Elkhart Lake Raag Jadav
2024-02-08 17:20   ` Andy Shevchenko
2024-02-09 19:18     ` Raag Jadav
2024-02-09 19:41       ` Andy Shevchenko
2024-02-10 17:19         ` Uwe Kleine-König
2024-02-12 11:53           ` Andy Shevchenko
2024-02-08  7:05 ` [PATCH v2 3/5] pwm: dwc: simplify error handling Raag Jadav
2024-02-08 17:22   ` Andy Shevchenko
2024-02-09 20:33     ` Raag Jadav
2024-02-12 11:52       ` Andy Shevchenko
2024-02-08  7:05 ` [PATCH v2 4/5] pwm: dwc: access driver_data using dev_get_drvdata() Raag Jadav
2024-02-08  7:05 ` [PATCH v2 5/5] pwm: dwc: use pm_sleep_ptr() macro Raag Jadav
2024-02-08 17:22   ` Andy Shevchenko
2024-02-15 11:22     ` Uwe Kleine-König
2024-02-08 17:23 ` [PATCH v2 0/5] DesignWare PWM improvements Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zcz-csPY5x29DP7v@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=lakshmi.sowjanya.d@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=raag.jadav@intel.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox