From patchwork Tue Oct 25 08:50:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matti Vaittinen X-Patchwork-Id: 13018758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E8C9C38A2D for ; Tue, 25 Oct 2022 08:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbiJYIvS (ORCPT ); Tue, 25 Oct 2022 04:51:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231918AbiJYIvJ (ORCPT ); Tue, 25 Oct 2022 04:51:09 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE83100BEF; Tue, 25 Oct 2022 01:51:06 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id bn35so7203826ljb.5; Tue, 25 Oct 2022 01:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=8R7Dzkg4GW8RstwwsY0aTGhaifKaL40i/WfeE85O4HQ=; b=M4gG5q52M/fQ9S4AOTPRH4k1dtWqpvOU0rll7wPOXPb3Bwet7P3t8f3mFv42GbrAy9 5EURqb4L7WnK/nC3JOiYfyGIGCDzWD4i6bHe0GX6e4/4fdYuaGk5orrzxKxmyHHnH1zN u24zaLTaynom7ACPi3VX8hiX03meCkywL+o6ONYMDc5scpG5EccOSBdrcVeSalgbzLRA v5V3PsOAfFOcJUWy+q/jA/g+oCqwET8SAAEiVCdOT9tLmshrPsEBrUewWDE0z99G/q6B 4rxDuEI7l8y/uV0E2Kinc6RPR7lKpJkMy3zF8fYozGaU+HIIUXEuq5+s56J/W0PPufAg Gp3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=8R7Dzkg4GW8RstwwsY0aTGhaifKaL40i/WfeE85O4HQ=; b=WjJnxSb30D1Za/VjN+lzib1JeT0D1FITxn53zBKuM9pWP1rAuJuPzVcdZ1b2K8AUKf tP56pn/17WP3s7VM8We1wasPGpJvpu+R5sxFhwhMSNCXo5C9i4lYmVKoXBCmHMWH3FjX YWPCmcayDn/Cof7ZrBoo9i3fvZKecaWhZcHfBBoMpCdPW6Dlb1YcVzGcAJfkPh8RsA2w qPTauK9cNYCaP4w3nmVLxQokF/EljO9lRSKrJE4/EIN9muNORRu4cKHdI/DbrVmSNnZF Rz0X2qSuGTxUEO575l1dW5GlfDm6/ZM4Zrjtly60V5iw9Q9oppxUD5O6PEQzWuCcbNbI kIeQ== X-Gm-Message-State: ACrzQf06MhXtJNTKCnqaeQHB853PyXS8rulsC0dffQ/G/+WLrMAg23qZ YzZ8GygLwV1Y19MRf8X6ydRlLod0FC0= X-Google-Smtp-Source: AMsMyM7n1L9PPIffLH1ajY4W5iGiaOUMO2bRde9qkIiM0wgTpAlSYIFbHPglgLZnhCsLvU6I+4GokQ== X-Received: by 2002:a2e:9b17:0:b0:26e:367c:c904 with SMTP id u23-20020a2e9b17000000b0026e367cc904mr14717348lji.326.1666687864570; Tue, 25 Oct 2022 01:51:04 -0700 (PDT) Received: from dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi (dc75zzyyyyyyyyyyyyyby-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::2]) by smtp.gmail.com with ESMTPSA id m4-20020a056512114400b0049b8c0571e5sm326150lfg.113.2022.10.25.01.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Oct 2022 01:51:03 -0700 (PDT) Date: Tue, 25 Oct 2022 11:50:59 +0300 From: Matti Vaittinen To: Matti Vaittinen , Matti Vaittinen Cc: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Wolfram Sang , Akhil R , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [PATCH 1/2] drivers: fwnode: fix fwnode_irq_get_byname() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The fwnode_irq_get_byname() does return 0 upon device-tree IRQ mapping failure. This is contradicting the function documentation and can potentially be a source of errors like: int probe(...) { ... irq = fwnode_irq_get_byname(); if (irq <= 0) return irq; ... } Here we do correctly check the return value from fwnode_irq_get_byname() but the driver probe will now return success. (There was already one such user in-tree). Change the fwnode_irq_get_byname() to work as documented and according to the common convention and abd always return a negative errno upon failure. Fixes: ca0acb511c21 ("device property: Add fwnode_irq_get_byname") Suggested-by: Sakari Ailus Signed-off-by: Matti Vaittinen Reviewed-by: Sakari Ailus --- I did a quick audit for the callers at v6.1-rc2: drivers/i2c/i2c-smbus.c drivers/iio/accel/adxl355_core.c drivers/iio/gyro/fxas21002c_core.c drivers/iio/imu/adis16480.c drivers/iio/imu/bmi160/bmi160_core.c drivers/iio/imu/bmi160/bmi160_core.c I did not spot any errors to be caused by this change. There will be a functional change in i2c-smbus.c as the probe will now return -EINVAL should the IRQ dt-mapping fail. It'd be nice if this was checked to be Ok by the peeps knowing the i2c-smbus :) --- drivers/base/property.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 4d6278a84868..bfc6c7286db2 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -964,7 +964,7 @@ EXPORT_SYMBOL(fwnode_irq_get); */ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) { - int index; + int index, ret; if (!name) return -EINVAL; @@ -973,7 +973,12 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name) if (index < 0) return index; - return fwnode_irq_get(fwnode, index); + ret = fwnode_irq_get(fwnode, index); + + if (!ret) + return -EINVAL; + + return ret; } EXPORT_SYMBOL(fwnode_irq_get_byname);