From patchwork Wed Jun 26 22:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 807651 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBB0318C359; Wed, 26 Jun 2024 22:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719440139; cv=none; b=OSTyJGc8Kn3JX6fcD7uiWWqyaX0X/T9DzOBbbvh0FBDwAy0iyHS4gZ3EGd61qf2qxs+kvC7kQa1lFDG5Dcf3eD+g6TRTgmor7eWGo0dFEQQUUoOFMoqqUflhkpg36UO4mtiwgfs+PdMunAf12EF8I6MEvHo3RL1AXXNQylixFj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719440139; c=relaxed/simple; bh=RXBdILgDC90ocBfwyY5fxERS674LRoG10dOB+6UhB5s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bqzkt8fixnARFhBPC8aRTGgSIBh7+IMiO4ARgki7A1UA0cpJLFvzv+FyAVK/37987DruKvoJVPC8XCVC8GFmWjnDZdI2qwvk23aYiat2ZEcu93byTjK6NAezodYdUGPuzdjKu8wg6uuJk8jogjZInI1zhPctYj0tpxU1be4QGPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JXoO8CRX; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JXoO8CRX" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-362b32fbb3bso4638907f8f.2; Wed, 26 Jun 2024 15:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719440136; x=1720044936; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kLTQuTfeMs6giWphiXNYhP8ADsgQDsBUoWfBhccu/sM=; b=JXoO8CRXgBkNeBZBkW6xlvZMammJsdpmtnx9qQ8mNclGt6kJ9Ugn93oX8Bimg1ELUQ LDObRjGVIKfyzkr/rFG+6gbbb1ays7GhVdH0HhTAjBX/YnbIXUGWuO2jdXgnhb0Bn8w+ Sdki3gR48uNTnJ/MPvtP6ED9R7gsPA5K4UNZgkRojMgwvuq/iyXK78CBR0I2imIPEKUf arL7Gztsszam98Q0uH8dwKS8U3NpNYLTAK2BZGODgXTwISOWV9EQDw9QKLGD2OcQepWG LnvuUpMvuwdWgZMd6zxWz4pN6R/VX07pqZb3FKLQPxeOobYZVqh4iLnceDpR9UUqi17w 2tzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719440136; x=1720044936; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kLTQuTfeMs6giWphiXNYhP8ADsgQDsBUoWfBhccu/sM=; b=pz+UHTdHn7jAkrxQJC6TMai3WsShRDMtSvjUiS2jXA8qPYyQZf9sd4mvOTeau9GbFB rvJi1oaj9Nfkhd0p3PLHTWAagNcwy5hWwyGJrpCkX/VXn0NT+73KOcOF1AkdxLV13+Jx oZtVQkn+p+sUPaI54BlOHBD+3ntNYYLiBD+l9ONjYUBkMQSKGiY5WythVPyxWtei486e 7AA4/Iq/PgHSHEsj14SLlkpd0z9ZK2SEWxiGyrUDjqDIIYkQLqm34HgTspWwrPENgXF/ 4nTaggUkl0GXfUUbYd8VvJ3rCoZK7mRw/lnotf1w0Qwhp2bYv/dc5GmRYyi5ZyW1p5Ne zHMA== X-Forwarded-Encrypted: i=1; AJvYcCU8Qs8VGE0Gx/bLu0bW1VrKEZXzHpAKYoA3j60MWPMOW7aSzy/2dy0Ujp9vC6cJr7Uc6QvLOmED9dM+cyAbCYALftamf/sWYgPCA5Bka+1cigF7Ii7gn2pPrIXAjXWzR6xOxSGbBHyHyw== X-Gm-Message-State: AOJu0Yx2iq8REtgkwTtC3974iVki5y+WP3mdtybDOwHrJ/ZKZljRuWRM I/3JON4tYaQ5vnpuJh8WrsG+4nMQGjGMLC2L8n/+dBbGIy3c03ee6rZTvA== X-Google-Smtp-Source: AGHT+IEfnomeJyZ9CS55oJKSbamF/nbdmSjmqEXRswhyH9Ys4tnI4cBY85jfbQ8qzYZ0WYSXfftF3Q== X-Received: by 2002:adf:fa8e:0:b0:362:8749:9639 with SMTP id ffacd0b85a97d-366e7a373f4mr7792765f8f.35.1719440135963; Wed, 26 Jun 2024 15:15:35 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3674357c100sm39283f8f.21.2024.06.26.15.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 15:15:35 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH 1/3] leds: leds-lp5569: Convert to sysfs_emit API Date: Thu, 27 Jun 2024 00:15:11 +0200 Message-ID: <20240626221520.2846-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert sprintf to the much safer sysfs_emit API to handle output for sysfs. Also better handle situation where on the same chip there may be LED open and shorted at the same time. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5569.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c index 7ccd8dd6026a..e5e7e61c8916 100644 --- a/drivers/leds/leds-lp5569.c +++ b/drivers/leds/leds-lp5569.c @@ -268,8 +268,8 @@ static ssize_t lp5569_led_open_test(struct lp55xx_led *led, char *buf) led_tmp = led; for (i = 0; i < pdata->num_channels; i++) { if (leds_fault[led_tmp->chan_nr]) - pos += sprintf(buf + pos, "LED %d OPEN FAIL\n", - led_tmp->chan_nr); + pos += sysfs_emit_at(buf, pos, "LED %d OPEN FAIL\n", + led_tmp->chan_nr); led_tmp++; } @@ -366,8 +366,8 @@ static ssize_t lp5569_led_short_test(struct lp55xx_led *led, char *buf) led_tmp = led; for (i = 0; i < pdata->num_channels; i++) { if (leds_fault[led_tmp->chan_nr]) - pos += sprintf(buf + pos, "LED %d SHORTED FAIL\n", - led_tmp->chan_nr); + pos += sysfs_emit_at(buf, pos, "LED %d SHORTED FAIL\n", + led_tmp->chan_nr); led_tmp++; } @@ -404,7 +404,7 @@ static ssize_t lp5569_selftest(struct device *dev, goto fail; /* Test LED Shorted */ - pos = lp5569_led_short_test(led, buf); + pos += lp5569_led_short_test(led, buf); if (pos < 0) goto fail; @@ -420,10 +420,10 @@ static ssize_t lp5569_selftest(struct device *dev, } if (pos == 0) - pos = sprintf(buf, "OK\n"); + pos = sysfs_emit(buf, "OK\n"); goto release_lock; fail: - pos = sprintf(buf, "FAIL\n"); + pos = sysfs_emit(buf, "FAIL\n"); release_lock: mutex_unlock(&chip->lock); From patchwork Wed Jun 26 22:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 808580 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66136192B88; Wed, 26 Jun 2024 22:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719440140; cv=none; b=rR5KTp177k2bu5cIR0UISataNu4YTpVBmxpJzAijNrc9VMTY05JARmAdsF6nP2iXclx7yrMSMnjYzJqLkFhlAr4cLGrVwj+Ft3bcLVq6hCpjJjZccBDrxA/izgdgsZtJmxdftcpCuvBybUPDz81MvuAlIbmGcWBm8wLp5VTCNqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719440140; c=relaxed/simple; bh=wFDFHqhS3qX5NCIpgbyYbFWvakVs0ekaPkLcrqR777I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q3H3H1SRIYdKB9Z+/ZSNh7NFt/HrhT3PDOJDH+nZO2EPgtSw2AaTWLXpiX2Ci6pJaU0sqjezDb03OO3FYoCOb+FVrtaai9TAzL1xomtkCPOJEVl0rEqkzHZmY6fEGAEOYVwkrbR2lm1+eVXgqKwXEU+BjbFKz62Niq45vMmQDUU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aXkt97e3; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aXkt97e3" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-35f2c9e23d3so697754f8f.0; Wed, 26 Jun 2024 15:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719440137; x=1720044937; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aiix5Xrz7t/WrX8YaUt6vIhavBZv3X1aF7zRD7XM1HE=; b=aXkt97e33IHSe0fXF7ha3jZKiSbrETC4/Dxs9+MsnyfHkdIhL1Ieg0fOALvUT2dJTQ 2XsA8cOdeSmRMPUhQVwb3wz2r3gQLU5swwybvmyDTA8On9S5azU38ot+phVbe54QQX9U vxmmu2kljs7PdTthXRgPBjaA/O4aNnE0p2SLj4DepkPPMbqXKSgaOWxK7wrbRnmYGH6l /d1Nshc0ksiuKzZv/dWgFyak969QKTg2souDWtIuNjc/aj2F+7pblGjLeNNTdrWRf6Jh Ljuys1mWDZPiv9Y5qHWlqqi3gaGjILN8aWPtM/9N2rG4CtEEsNjaRLJdXJqvLE0flhFJ mt5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719440137; x=1720044937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aiix5Xrz7t/WrX8YaUt6vIhavBZv3X1aF7zRD7XM1HE=; b=ofsk6lNVLA1KRM2Tw9LFG8c8BuVvYqmUkNCuoiHNmVDqioAqOCuZKAz/HD+lpqn/lA CT7Byevlto1tTbzpRALKA3v3xKugAlac2uV+0w9k2qRFk92uQuCxJ6Lfx3djakincHUh 7nBxqTohTKbAEa/kPQXu4oRo1DekSV+2deVePWDD5NwUHbl3tWmIfdcwqPvjnKWNgidA mzVT0gRPQh2YQh0Q+tYWv3lnFtNu30EOckMkGQu9PTUb8eUThLUHIo077d8KpJI7ZlR1 b1O42RhQYqmegXp+K1pfVsqbTyM1yFmetd9wHJ2XIFErOWErKZmyBrclg7+lInA0p2Ec klgA== X-Forwarded-Encrypted: i=1; AJvYcCVWpBn0DPTnFrOKseTB2a0FNm1280Di4K2psyKMDHDGEIqRWJm0UMr2wruN5jakjRiKe2UyvJOsSlaOyj+valpqg9GksNY4mMkA9kTTXSKmz9n/hi8v1OwLz3BAd/TOHUsbdrlROBz3EA== X-Gm-Message-State: AOJu0YyNq3GoHvnmomG4Z3vZCLL1OmRjMEmnXTvM5mKY9U+hy6iqGZaE cGvU9zasCE0piWQ40f4DBVFTRIc72ZVefwKlnX7AZjc/9gWqw1Hp X-Google-Smtp-Source: AGHT+IF8L7ntxR7p+85JVF3C8lAvwLmsQbBsn0550zz8rDqdsMrD/08gyhzRrwsKzJSeB1P4N/X6nA== X-Received: by 2002:a5d:504b:0:b0:35f:fd7:6102 with SMTP id ffacd0b85a97d-3673cc95911mr608018f8f.35.1719440136724; Wed, 26 Jun 2024 15:15:36 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3674357c100sm39283f8f.21.2024.06.26.15.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 15:15:36 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi Subject: [PATCH 2/3] leds: leds-lp5523: Convert to sysfs_emit API Date: Thu, 27 Jun 2024 00:15:12 +0200 Message-ID: <20240626221520.2846-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240626221520.2846-1-ansuelsmth@gmail.com> References: <20240626221520.2846-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert sprintf to the much safer sysfs_emit API to handle output for sysfs. Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5523.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 57df920192d2..095060533d1a 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -245,8 +245,8 @@ static ssize_t lp5523_selftest(struct device *dev, goto fail; if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM) - pos += sprintf(buf + pos, "LED %d FAIL\n", - led->chan_nr); + pos += sysfs_emit_at(buf, pos, "LED %d FAIL\n", + led->chan_nr); lp55xx_write(chip, LP5523_REG_LED_PWM_BASE + led->chan_nr, 0x00); @@ -257,10 +257,10 @@ static ssize_t lp5523_selftest(struct device *dev, led++; } if (pos == 0) - pos = sprintf(buf, "OK\n"); + pos = sysfs_emit(buf, "OK\n"); goto release_lock; fail: - pos = sprintf(buf, "FAIL\n"); + pos = sysfs_emit(buf, "FAIL\n"); release_lock: mutex_unlock(&chip->lock); From patchwork Wed Jun 26 22:15:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 807650 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86B1819309B; Wed, 26 Jun 2024 22:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719440141; cv=none; b=ewmKZ5oGUA5VGZx6gHnbI1Zbkfr9lYZvgfbgA4R/tD7vwP+gH8gdmy+uueMSr7TTbracZ3g+SH11aV6hQuVa46ahOaQQxXddYhvm/Nt1ncQ0NMLwOHg8eELKBUXAJVDfAkmDqrTwfucy2FKuJeobKUrCSCwP3kcsfYPVlIEmtbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719440141; c=relaxed/simple; bh=euD8H9nhTWjMYgaFrJyGcZpK5f7HZBYh2TkuafSVTXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Yrwoaw7uH9niDOIiH/gzshgg/kxyTPPeDfiG0k4lnvZyNEExGWSo/n4W6s4lF/Q70prdsBapshguUJHuEfEOXfLxtoDsGrW1NuPUMcWwbfm//ah7A4wkjSJS7mFv/eRcTVGXFlJX+Kf2met5k4gPegiW8PtFpt558ewm2DJjdo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hw72Za3T; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hw72Za3T" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-42108856c33so7071055e9.1; Wed, 26 Jun 2024 15:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719440138; x=1720044938; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iYxBdR+wOFYbAoJ4+ERABgkCtVZGe8zC55wy5HLb/Rs=; b=Hw72Za3TifFCvH12oNg4ClpsoVUU91WZg7cOPOiWf96ejFNMzDZzQ1dkvbBqsSd1WI z8iy+7pla2lBf/ds1QfD1WbE+4iJDBSJgshXPDRLWF3b/26s3tgIPRDB/FdCEwubChHd ju8kNgnfmCS4g0Kdl8q340QwEzkre+cv8/hf27Ci7c1jeJ5OfVcXE3lh+GvYDeSwzx4I aoOTfQs4xnJX0eowIANBenlVouqe3C6U3OJ4rnutlB9uH+Rwl5ma353sLXAX1A6jmQew Aruvi8Phptlkt4PHmaDsDb05Fioo9FSqbOl4n4IYDk+pbo56AqgFCpw9R/06BzHnEIxo R8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719440138; x=1720044938; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iYxBdR+wOFYbAoJ4+ERABgkCtVZGe8zC55wy5HLb/Rs=; b=NZE5+gLLkUaGOrl6FwzC9gmD8l1nnSKp48gpiSmyPctVeV7+HsXk7mBWFqmZzeLU+9 1IeKRKZdXY2HmBbVhpGgLDR9w7XYHE0EcnUq4MLlj3RgkaB5a3cgmALyzpY40hnIO+6c NbFxvzz6rxMK3YEfyj5iNJ0BtpmWLBlJ6jGlofgBfzf8I6miCtK5UJO/6x+ICqXQ/kqo snDzlsxUS0U70Izi0Y1DdudZM0j2YbOSfuwMsTleY/5ZnOHXxEldYuB0GY0EJfDfB31D ocNF7rkMQuLZRaJBhbia2417CIpMVUcJYbjvCUGWLPopIp/LeUbiU+d3C2POHrU7F6yf sKGQ== X-Forwarded-Encrypted: i=1; AJvYcCXRmBothi/eRyrXRhcx9cup8uMcQR2aTa7G7LABrDcnw7V3XcJ1sNUaYznPcI0z+fi2tZyCeojduO03c1ejWFotyyxJSyXna9hq6LkoqDuUIcN2PpwvNgmyhrpWhdwNz4CmjVEf/qwVaA== X-Gm-Message-State: AOJu0Yw0HhYTOKFMtZjDctQgU23UdgclJ96O0LuJy9q7PZq7FCawBP20 Xzw8A5xuDa51GJjR86h9x2UnSfvq056AUcP/4qkdWt8gMAjgG+Hl X-Google-Smtp-Source: AGHT+IGCpsc3L7v8ad+FUI3szjdD1TyNX6xJCCgi6F/r+g0P+IyHhf16nibF7z33+ipx6kZugvzl7A== X-Received: by 2002:a5d:6d04:0:b0:366:eadc:573f with SMTP id ffacd0b85a97d-367419135c5mr161449f8f.27.1719440137638; Wed, 26 Jun 2024 15:15:37 -0700 (PDT) Received: from localhost.localdomain (93-34-90-105.ip49.fastwebnet.it. [93.34.90.105]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3674357c100sm39283f8f.21.2024.06.26.15.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 15:15:37 -0700 (PDT) From: Christian Marangi To: Pavel Machek , Lee Jones , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Christian Marangi , Markus Elfring Subject: [PATCH 3/3] leds: leds-lp55xx: Convert mutex lock/unlock to guard API Date: Thu, 27 Jun 2024 00:15:13 +0200 Message-ID: <20240626221520.2846-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240626221520.2846-1-ansuelsmth@gmail.com> References: <20240626221520.2846-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert any entry of mutex lock/unlock to guard API and simplify code. With the use of guard API, handling for selttest functions can be greatly simplified. Suggested-by: Markus Elfring Signed-off-by: Christian Marangi --- drivers/leds/leds-lp5521.c | 5 +- drivers/leds/leds-lp5523.c | 25 +++----- drivers/leds/leds-lp5562.c | 13 +++-- drivers/leds/leds-lp5569.c | 18 ++---- drivers/leds/leds-lp55xx-common.c | 94 +++++++++++++------------------ 5 files changed, 64 insertions(+), 91 deletions(-) diff --git a/drivers/leds/leds-lp5521.c b/drivers/leds/leds-lp5521.c index de0f8ea48eba..56d16ea18617 100644 --- a/drivers/leds/leds-lp5521.c +++ b/drivers/leds/leds-lp5521.c @@ -9,6 +9,7 @@ * Milo(Woogyom) Kim */ +#include #include #include #include @@ -185,9 +186,9 @@ static ssize_t lp5521_selftest(struct device *dev, struct lp55xx_chip *chip = led->chip; int ret; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + ret = lp5521_run_selftest(chip, buf); - mutex_unlock(&chip->lock); return sysfs_emit(buf, "%s\n", ret ? "FAIL" : "OK"); } diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c index 095060533d1a..baa1a3ac1a56 100644 --- a/drivers/leds/leds-lp5523.c +++ b/drivers/leds/leds-lp5523.c @@ -9,6 +9,7 @@ * Milo(Woogyom) Kim */ +#include #include #include #include @@ -188,16 +189,16 @@ static ssize_t lp5523_selftest(struct device *dev, int ret, pos = 0; u8 status, adc, vdd, i; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); ret = lp55xx_read(chip, LP5523_REG_STATUS, &status); if (ret < 0) - goto fail; + return sysfs_emit(buf, "FAIL\n"); /* Check that ext clock is really in use if requested */ if (pdata->clock_mode == LP55XX_CLOCK_EXT) { if ((status & LP5523_EXT_CLK_USED) == 0) - goto fail; + return sysfs_emit(buf, "FAIL\n"); } /* Measure VDD (i.e. VBAT) first (channel 16 corresponds to VDD) */ @@ -205,14 +206,14 @@ static ssize_t lp5523_selftest(struct device *dev, usleep_range(3000, 6000); /* ADC conversion time is typically 2.7 ms */ ret = lp55xx_read(chip, LP5523_REG_STATUS, &status); if (ret < 0) - goto fail; + return sysfs_emit(buf, "FAIL\n"); if (!(status & LP5523_LEDTEST_DONE)) usleep_range(3000, 6000); /* Was not ready. Wait little bit */ ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &vdd); if (ret < 0) - goto fail; + return sysfs_emit(buf, "FAIL\n"); vdd--; /* There may be some fluctuation in measurement */ @@ -235,14 +236,14 @@ static ssize_t lp5523_selftest(struct device *dev, usleep_range(3000, 6000); ret = lp55xx_read(chip, LP5523_REG_STATUS, &status); if (ret < 0) - goto fail; + return sysfs_emit(buf, "FAIL\n"); if (!(status & LP5523_LEDTEST_DONE)) usleep_range(3000, 6000); /* Was not ready. Wait. */ ret = lp55xx_read(chip, LP5523_REG_LED_TEST_ADC, &adc); if (ret < 0) - goto fail; + return sysfs_emit(buf, "FAIL\n"); if (adc >= vdd || adc < LP5523_ADC_SHORTCIRC_LIM) pos += sysfs_emit_at(buf, pos, "LED %d FAIL\n", @@ -256,16 +257,8 @@ static ssize_t lp5523_selftest(struct device *dev, led->led_current); led++; } - if (pos == 0) - pos = sysfs_emit(buf, "OK\n"); - goto release_lock; -fail: - pos = sysfs_emit(buf, "FAIL\n"); -release_lock: - mutex_unlock(&chip->lock); - - return pos; + return pos == 0 ? sysfs_emit(buf, "OK\n") : pos; } LP55XX_DEV_ATTR_ENGINE_MODE(1); diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c index 6ba5dbb9cace..69a4e3d5a126 100644 --- a/drivers/leds/leds-lp5562.c +++ b/drivers/leds/leds-lp5562.c @@ -7,6 +7,7 @@ * Author: Milo(Woogyom) Kim */ +#include #include #include #include @@ -171,9 +172,9 @@ static int lp5562_led_brightness(struct lp55xx_led *led) }; int ret; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + ret = lp55xx_write(chip, addr[led->chan_nr], led->brightness); - mutex_unlock(&chip->lock); return ret; } @@ -268,9 +269,9 @@ static ssize_t lp5562_store_pattern(struct device *dev, if (mode > num_patterns || !ptn) return -EINVAL; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + ret = lp5562_run_predef_led_pattern(chip, mode); - mutex_unlock(&chip->lock); if (ret) return ret; @@ -320,9 +321,9 @@ static ssize_t lp5562_store_engine_mux(struct device *dev, return -EINVAL; } - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + lp55xx_update_bits(chip, LP5562_REG_ENG_SEL, mask, val); - mutex_unlock(&chip->lock); return len; } diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c index e5e7e61c8916..dc8efb25b78e 100644 --- a/drivers/leds/leds-lp5569.c +++ b/drivers/leds/leds-lp5569.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -396,17 +397,17 @@ static ssize_t lp5569_selftest(struct device *dev, struct lp55xx_chip *chip = led->chip; int i, pos = 0; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); /* Test LED Open */ pos = lp5569_led_open_test(led, buf); if (pos < 0) - goto fail; + return sprintf(buf, "FAIL\n"); /* Test LED Shorted */ pos += lp5569_led_short_test(led, buf); if (pos < 0) - goto fail; + return sprintf(buf, "FAIL\n"); for (i = 0; i < chip->pdata->num_channels; i++) { /* Restore current */ @@ -419,16 +420,7 @@ static ssize_t lp5569_selftest(struct device *dev, led++; } - if (pos == 0) - pos = sysfs_emit(buf, "OK\n"); - goto release_lock; -fail: - pos = sysfs_emit(buf, "FAIL\n"); - -release_lock: - mutex_unlock(&chip->lock); - - return pos; + return pos == 0 ? sysfs_emit(buf, "OK\n") : pos; } LP55XX_DEV_ATTR_ENGINE_MODE(1); diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c index 1b71f512206d..f8cf5c0e983a 100644 --- a/drivers/leds/leds-lp55xx-common.c +++ b/drivers/leds/leds-lp55xx-common.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -272,10 +273,10 @@ int lp55xx_led_brightness(struct lp55xx_led *led) const struct lp55xx_device_config *cfg = chip->cfg; int ret; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + ret = lp55xx_write(chip, cfg->reg_led_pwm_base.addr + led->chan_nr, led->brightness); - mutex_unlock(&chip->lock); return ret; } EXPORT_SYMBOL_GPL(lp55xx_led_brightness); @@ -287,7 +288,8 @@ int lp55xx_multicolor_brightness(struct lp55xx_led *led) int ret; int i; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + for (i = 0; i < led->mc_cdev.num_colors; i++) { ret = lp55xx_write(chip, cfg->reg_led_pwm_base.addr + @@ -296,7 +298,7 @@ int lp55xx_multicolor_brightness(struct lp55xx_led *led) if (ret) break; } - mutex_unlock(&chip->lock); + return ret; } EXPORT_SYMBOL_GPL(lp55xx_multicolor_brightness); @@ -404,9 +406,9 @@ static ssize_t led_current_store(struct device *dev, if (!chip->cfg->set_led_current) return len; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + chip->cfg->set_led_current(led, (u8)curr); - mutex_unlock(&chip->lock); return len; } @@ -541,14 +543,12 @@ static void lp55xx_firmware_loaded(const struct firmware *fw, void *context) } /* handling firmware data is chip dependent */ - mutex_lock(&chip->lock); - - chip->engines[idx - 1].mode = LP55XX_ENGINE_LOAD; - chip->fw = fw; - if (chip->cfg->firmware_cb) - chip->cfg->firmware_cb(chip); - - mutex_unlock(&chip->lock); + scoped_guard(mutex, &chip->lock) { + chip->engines[idx - 1].mode = LP55XX_ENGINE_LOAD; + chip->fw = fw; + if (chip->cfg->firmware_cb) + chip->cfg->firmware_cb(chip); + } /* firmware should be released for other channel use */ release_firmware(chip->fw); @@ -592,10 +592,10 @@ static ssize_t select_engine_store(struct device *dev, case LP55XX_ENGINE_1: case LP55XX_ENGINE_2: case LP55XX_ENGINE_3: - mutex_lock(&chip->lock); - chip->engine_idx = val; - ret = lp55xx_request_firmware(chip); - mutex_unlock(&chip->lock); + scoped_guard(mutex, &chip->lock) { + chip->engine_idx = val; + ret = lp55xx_request_firmware(chip); + } break; default: dev_err(dev, "%lu: invalid engine index. (1, 2, 3)\n", val); @@ -634,9 +634,9 @@ static ssize_t run_engine_store(struct device *dev, return len; } - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + lp55xx_run_engine(chip, true); - mutex_unlock(&chip->lock); return len; } @@ -673,7 +673,7 @@ ssize_t lp55xx_store_engine_mode(struct device *dev, const struct lp55xx_device_config *cfg = chip->cfg; struct lp55xx_engine *engine = &chip->engines[nr - 1]; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); chip->engine_idx = nr; @@ -689,8 +689,6 @@ ssize_t lp55xx_store_engine_mode(struct device *dev, engine->mode = LP55XX_ENGINE_DISABLED; } - mutex_unlock(&chip->lock); - return len; } EXPORT_SYMBOL_GPL(lp55xx_store_engine_mode); @@ -703,14 +701,12 @@ ssize_t lp55xx_store_engine_load(struct device *dev, struct lp55xx_chip *chip = led->chip; int ret; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); chip->engine_idx = nr; lp55xx_load_engine(chip); ret = lp55xx_update_program_memory(chip, buf, len); - mutex_unlock(&chip->lock); - return ret; } EXPORT_SYMBOL_GPL(lp55xx_store_engine_load); @@ -804,21 +800,17 @@ ssize_t lp55xx_store_engine_leds(struct device *dev, if (lp55xx_mux_parse(chip, buf, &mux, len)) return -EINVAL; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); chip->engine_idx = nr; - ret = -EINVAL; if (engine->mode != LP55XX_ENGINE_LOAD) - goto leave; + return -EINVAL; if (lp55xx_load_mux(chip, mux, nr)) - goto leave; + return -EINVAL; - ret = len; -leave: - mutex_unlock(&chip->lock); - return ret; + return len; } EXPORT_SYMBOL_GPL(lp55xx_store_engine_leds); @@ -832,9 +824,9 @@ ssize_t lp55xx_show_master_fader(struct device *dev, int ret; u8 val; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + ret = lp55xx_read(chip, cfg->reg_master_fader_base.addr + nr - 1, &val); - mutex_unlock(&chip->lock); return ret ? ret : sysfs_emit(buf, "%u\n", val); } @@ -856,10 +848,10 @@ ssize_t lp55xx_store_master_fader(struct device *dev, if (val > 0xff) return -EINVAL; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); + ret = lp55xx_write(chip, cfg->reg_master_fader_base.addr + nr - 1, (u8)val); - mutex_unlock(&chip->lock); return ret ? ret : len; } @@ -875,25 +867,22 @@ ssize_t lp55xx_show_master_fader_leds(struct device *dev, int i, ret, pos = 0; u8 val; - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); for (i = 0; i < cfg->max_channel; i++) { ret = lp55xx_read(chip, cfg->reg_led_ctrl_base.addr + i, &val); if (ret) - goto leave; + return ret; val = FIELD_GET(LP55xx_FADER_MAPPING_MASK, val); if (val > FIELD_MAX(LP55xx_FADER_MAPPING_MASK)) { - ret = -EINVAL; - goto leave; + return -EINVAL; } buf[pos++] = val + '0'; } buf[pos++] = '\n'; - ret = pos; -leave: - mutex_unlock(&chip->lock); - return ret; + + return pos; } EXPORT_SYMBOL_GPL(lp55xx_show_master_fader_leds); @@ -909,7 +898,7 @@ ssize_t lp55xx_store_master_fader_leds(struct device *dev, n = min_t(int, len, cfg->max_channel); - mutex_lock(&chip->lock); + guard(mutex, &chip->lock); for (i = 0; i < n; i++) { if (buf[i] >= '0' && buf[i] <= '3') { @@ -919,16 +908,13 @@ ssize_t lp55xx_store_master_fader_leds(struct device *dev, LP55xx_FADER_MAPPING_MASK, val); if (ret) - goto leave; + return ret; } else { - ret = -EINVAL; - goto leave; + return -EINVAL; } } - ret = len; -leave: - mutex_unlock(&chip->lock); - return ret; + + return len; } EXPORT_SYMBOL_GPL(lp55xx_store_master_fader_leds);