From patchwork Wed Aug 9 13:14:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 133266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2816087vqr; Wed, 9 Aug 2023 06:56:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG09HgtZgsJA2RgTu3e4KJn+jdG4bj9mK9Zvd9w2499Fwx8rRAIG8VG/GqTyPKxphJXCpF5 X-Received: by 2002:a05:6870:b295:b0:1bb:6485:7988 with SMTP id c21-20020a056870b29500b001bb64857988mr3385797oao.35.1691589397389; Wed, 09 Aug 2023 06:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691589397; cv=none; d=google.com; s=arc-20160816; b=Qa48z8fxjX5NlwkRfRXgsZEGO6Ru2jU3MrxwHHWM/X/JytWMAO+9kFuMPS/OVZsHFR mutqeOXkQZ3s7rmKyVz2lrrYbQesLO/KZjer5aQUU5yYlxyE8YY/jfyFAxV2Ea0ZHP7c 9uZe6iTqqu9ljLYhEUdd84CNf0rpxeP4L/NWpP67UPY/sXk2rii2ycTUQS38CR3uBb4n cMtyf53woR2xlLDaPN0k5EoHXGAPZrLZ0wZYmCM8Ql8MVLMSC+1afcgYr6bvst1yML7Q BnHI/W/H8cc2O8gnCmWY+aSYGkvEt7v+u8B95NBODzAMvMYIrz1rEwJdhf4Iebnvz8n3 eDjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7gMEpKFy6UqkVloE+P0Ccdw0TcVvUrsnSGcQwKKkLpg=; fh=rCqKS5Wgxyvu9nhWEkn7CU+OTiPpAXAWtEe1ogm7zOc=; b=DL894s9QjAH/61o78FjscU4HwXyWhN/wkKKice3+IsKY+xz/ud14MQWWapCJdyKWbL nqinm4yjBZ7ilikk8corQGhS+KlIwkTeTBICnqd5cK43NebfChWCpWi9vcszvCwVpftq 0pF3Tne1i2jgLirSAC57GptVx3crTT11wLE7ov1UWp5kjbJDQLbV+dNsrIHzqpcpDhDG rmemsDfd4HckkTnaE3FT6lKmvbHmMbMPJk6R1UoVguO+SC9+k+aI7F7awoMOrMFDu9bV FOmqvARguLisfgV7rmU+Ppau4F5AYJaEhG4SmvF7eDOWJ71Q1gcy0tOx3igXkkH383eK 0DFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b=VEzjKNOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bg26-20020a056a02011a00b00563eff1b064si9346953pgb.504.2023.08.09.06.56.23; Wed, 09 Aug 2023 06:56:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20221208.gappssmtp.com header.s=20221208 header.b=VEzjKNOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232770AbjHINO4 (ORCPT + 99 others); Wed, 9 Aug 2023 09:14:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbjHINOz (ORCPT ); Wed, 9 Aug 2023 09:14:55 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C375E5F for ; Wed, 9 Aug 2023 06:14:54 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3fbea147034so57590215e9.0 for ; Wed, 09 Aug 2023 06:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20221208.gappssmtp.com; s=20221208; t=1691586893; x=1692191693; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=7gMEpKFy6UqkVloE+P0Ccdw0TcVvUrsnSGcQwKKkLpg=; b=VEzjKNOWVO2zUSd3wvUmHkJLAB5ce68Q8Q0Y2Xi492oiqKrX3dCss8jwR5iSaqBShW QDbIZiX+MCQ7BXMIwQys2a+TXDo/6q72iNc57OnZwG4T6IeJncz8/5xEGTpgwMwA9vLR bq/XZKHUBvGnSqPDr0oFXI2Lmn6dqz5kxn0NQm6y6GHIzVl2PfcP9vj9GdJrOkqzoak+ tsLKExX4t2G4jHTZ+9tew5PZL0s0kCv7X6JelmhVe97npha5JckPjCpxPKvtgKAm5P9z 2b6mNbvSsVHTkz7P3UPwfnZ7vcEOGkG0y7zIF4NLTMALMDdJhLZUbsQrWEDmSDGYokni J3Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691586893; x=1692191693; 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=7gMEpKFy6UqkVloE+P0Ccdw0TcVvUrsnSGcQwKKkLpg=; b=WazDj5ADQKAJBcZ9EtxhI6YACCO+nNWZE7xlyVxVMbssewNL7o8tsC85IvG46Lztzi c15HGUh1ichNQlukQW9W9/PWrybxPHWgKorL4BvahLX7xAyIPe4AawI7Qzrsj5JFPCqf cxt9fkddtJ6xr0wB3Wu5UaBYw6kTQOJ1+v3JgyeLOdeidfiE6d0X5eRrzrYAamIf1XMv q0Q2atH8BVbV2kcg8M7bHUxOBq9iQNS8NDZiu+aJbH0RPiSBv2a4QmtJhu5p5KMo70pK u253FgQfsHUbxZ4IKsV5d156ZGTjUi4izUjQYBTzmslC4y8MMqA1/cV+OJTtQjuN7ogi GQBQ== X-Gm-Message-State: AOJu0Yytp108gwTrpkUpsPpuTvUdScDUNMBpbttqlJ3UhNS5eIlDiURt z1jQQa8E5d5rAJ6HggkXgAdSMQ== X-Received: by 2002:a05:600c:22d8:b0:3fe:3004:1ffd with SMTP id 24-20020a05600c22d800b003fe30041ffdmr2233608wmg.4.1691586893062; Wed, 09 Aug 2023 06:14:53 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:bf0d:f784:9c7e:dd22]) by smtp.gmail.com with ESMTPSA id n1-20020a5d67c1000000b0031134bcdacdsm16741185wrw.42.2023.08.09.06.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 06:14:52 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Kent Gibson Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/2] gpio: sim: use sysfs_streq() and avoid an strdup() Date: Wed, 9 Aug 2023 15:14:41 +0200 Message-Id: <20230809131442.25524-1-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773760043667119525 X-GMAIL-MSGID: 1773760043667119525 From: Bartosz Golaszewski When comparing strings passed to us from configfs, we can pass the page argument directly to sysfs_streq() and avoid manual string trimming. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko --- drivers/gpio/gpio-sim.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 8b49b0abacd5..dc4097dc0fbc 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -1272,7 +1272,6 @@ gpio_sim_hog_config_direction_store(struct config_item *item, { struct gpio_sim_hog *hog = to_gpio_sim_hog(item); struct gpio_sim_device *dev = gpio_sim_hog_get_device(hog); - char *trimmed; int dir; mutex_lock(&dev->lock); @@ -1282,23 +1281,15 @@ gpio_sim_hog_config_direction_store(struct config_item *item, return -EBUSY; } - trimmed = gpio_sim_strdup_trimmed(page, count); - if (!trimmed) { - mutex_unlock(&dev->lock); - return -ENOMEM; - } - - if (strcmp(trimmed, "input") == 0) + if (sysfs_streq(page, "input")) dir = GPIOD_IN; - else if (strcmp(trimmed, "output-high") == 0) + else if (sysfs_streq(page, "output-high")) dir = GPIOD_OUT_HIGH; - else if (strcmp(trimmed, "output-low") == 0) + else if (sysfs_streq(page, "output-low")) dir = GPIOD_OUT_LOW; else dir = -EINVAL; - kfree(trimmed); - if (dir < 0) { mutex_unlock(&dev->lock); return dir;