From patchwork Fri May 29 22:03:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 246852 List-Id: U-Boot discussion From: p.yadav at ti.com (Pratyush Yadav) Date: Sat, 30 May 2020 03:33:54 +0530 Subject: [RFC PATCH 0/1] gpio: Handle NULL pointers gracefully Message-ID: <20200529220355.4396-1-p.yadav@ti.com> Hi, Patch [0] added devm_gpiod_get_index_optional() which would return NULL when when no GPIO was assigned to the requested function. This is convenient for drivers that need to handle optional GPIOs. We need to take a stance on who is responsible for the NULL check: the driver or the GPIO core? Do we want to trust drivers to take care of the NULL checks, or do we want to distrust them and make sure they don't send us anything bogus in the GPIO core. Linux does not generally trust drivers and usually verifies anything it gets from them. And FWIW, I see that the clk and phy subsystems in U-Boot also perform checks like this. The downside of the checks is of course that they increase code size. They might also slightly decrease performance. The benefit is that we don't burden drivers with taking care of this. The patch itself is based on a similar patch by Jean-Jacques. [0] https://patchwork.ozlabs.org/project/uboot/patch/20200529213808.2815-2-p.yadav at ti.com/ Pratyush Yadav (1): gpio: Handle NULL pointers gracefully drivers/gpio/Kconfig | 9 ++++ drivers/gpio/gpio-uclass.c | 86 ++++++++++++++++++++++++++++++++++---- include/asm-generic/gpio.h | 2 +- 3 files changed, 88 insertions(+), 9 deletions(-) --- 2.26.2