Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2652756pxb; Thu, 11 Feb 2021 19:37:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxTBYLPgmeRFESw7wl1coGWejDb/Om1DfIVo6a2q8xtn3YP3Sa/E7NJkaTt0rRe8iIvGkc X-Received: by 2002:aa7:da55:: with SMTP id w21mr1360927eds.138.1613101062254; Thu, 11 Feb 2021 19:37:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613101062; cv=none; d=google.com; s=arc-20160816; b=hb0X44HNenLMYH+fU2s3/aCTO85izjGQucFSMGOR0fU4yr0UlFW4KQyb2yGI/nJvq4 jdUuwdh8gIxqgkbJSkVNVU9O/Q6YNA9D2r9hHhxVJN8giuABOHV4tbinzM5E8h3xPpXG 9H/9FIGvXeLrfNLV8lxjraO5xBPrgT+XqGGOQLIDrpq96Dw4/aDn8GTS5vZjq9gYX+UG DXfTMHoACeVqnZdqmTDdA9YY3+E14vD1sVdIgdVLICZ9DnY6rPjcxbNEsIERJZOHOM7r HibYP2S+XqoT4OrudwDb2WTPvDK/0vi7o2hVzAejKFTSsUqyo/ph/Ul5FMx7ZV5QqUxu X7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FU6M+H964ngY0zpfpbcjRSHTk9tl8Qf14a9FzoajTy0=; b=yPOopvF6u3cFfbQeY7VRErrIIBWwU4hqH0G5hpkAbyv1qfFDL8rNO3xaZQprBOSRII fwUyhKDP1arSZoGHgZeTSRlDh+yTak+llj7KxspcVeAUJBk3lRAakmkoP3X42VeaQnoH hfuUrYfI3Ci1X79sGfUJVu7vq1uhS8lTKOz7bSaQL4aka0kh3m2kbsWxRnQKJQs/8f/T JosWUBGYtQRC+eFJcFhgIbhjsgGZqjpQsCTK0HBp2Kv67V2TSJUTvvmFu1AVsuDc2qcU jbZsEQSzASl5rStx8SIh4IiL5EQn+JRCSaxWDDHRluPiYyW5CwgIhR56CNlVatN2DebC 79tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b=YAgCHymo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e18si5697516edz.446.2021.02.11.19.37.17; Thu, 11 Feb 2021 19:37:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@beagleboard-org.20150623.gappssmtp.com header.s=20150623 header.b=YAgCHymo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229538AbhBLDgS (ORCPT + 99 others); Thu, 11 Feb 2021 22:36:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhBLDgR (ORCPT ); Thu, 11 Feb 2021 22:36:17 -0500 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 647D0C061574 for ; Thu, 11 Feb 2021 19:35:37 -0800 (PST) Received: by mail-pl1-x636.google.com with SMTP id z7so4419453plk.7 for ; Thu, 11 Feb 2021 19:35:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beagleboard-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FU6M+H964ngY0zpfpbcjRSHTk9tl8Qf14a9FzoajTy0=; b=YAgCHymoFMiybaEx8M86wrnBJWK+FetX/KrWwPlWv2jAsO4ynRIco23kUFw0tIeaI+ VvucPeKM63bfOzFDc71Svu3V0yF1oh4USkG1gbu7FkxtDhDNB4ELvLPvD21JGIl4FvHI rz9t920eozmBG0kWsot3K0MlzNxSZzfXvNrFEzkmZrNMYUFbdv026xSbvu2uFBq1r6k4 Cg8dkfqjZHUYxt/zVdOGre5S2DAn+qCL6Dlx/qUfBEZS9nekQGCSij2UcO0UkjpAa+Fv 0TLysYr0aezQ9niOkvJbNVinV2m00KOcxth5K33YMt6J2h+eV9ChTuYjzJ7XA/1Pgmj3 dJZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FU6M+H964ngY0zpfpbcjRSHTk9tl8Qf14a9FzoajTy0=; b=nU6o1/dSNBE55LBsgO6zH1fDa4x6b27EhqApIGI7YU52FIeZow2MEQRfUmkFBwM1Pi zTFUjQkksxw5MIE0yEnLWkcXfuj+lIYXJbfFR/lO+i/DxGYmKJtG+SHJFvkCt+eU5zv9 O2ujT7Gdk9kcuj5Gzmqt861sFBjNUzCaD3et9XMfaoaCoeYReJJoymQUWuwnRp/p86Ow zF/Fy4hIo8owHLuoPU/sENq6vZExIs6cwa8E6vM46i9wXya67hgXRgVk/wtizju7WQ33 NEOleQGhmX2t5wfOJOD56Egii53Yxh0GCK8nwIbk1PKHPrPNJ3OMEWDs1sVueclXouXx iMIg== X-Gm-Message-State: AOAM532HMIXznNNBMm8j5grnWv8K3IY6alb3gJmDqyzypxr09Cb9L5fe Mn1t1WLz4TwJKDrx34eGvySHBA== X-Received: by 2002:a17:90a:da02:: with SMTP id e2mr880989pjv.173.1613100936894; Thu, 11 Feb 2021 19:35:36 -0800 (PST) Received: from x1 ([2601:1c0:4701:ae70:3a7f:bbfb:1664:2a63]) by smtp.gmail.com with ESMTPSA id y16sm6964889pgg.20.2021.02.11.19.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 19:35:35 -0800 (PST) Date: Thu, 11 Feb 2021 19:35:33 -0800 From: Drew Fustini To: Dan Carpenter Cc: Joe Perches , Linus Walleij , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Lindgren , Andy Shevchenko , Alexandre Belloni , Geert Uytterhoeven , Pantelis Antoniou , Jason Kridner , Robert Nelson Subject: Re: [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Message-ID: <20210212033533.GA347396@x1> References: <20210210222851.232374-1-drew@beagleboard.org> <20210210222851.232374-3-drew@beagleboard.org> <20210211071153.GJ20820@kadam> <7b4105ca8671a2962910deb5418a934bf07d1458.camel@perches.com> <20210211073938.GL20820@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210211073938.GL20820@kadam> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2021 at 10:39:38AM +0300, Dan Carpenter wrote: > On Wed, Feb 10, 2021 at 11:24:23PM -0800, Joe Perches wrote: > > On Thu, 2021-02-11 at 10:11 +0300, Dan Carpenter wrote: > > > On Wed, Feb 10, 2021 at 02:28:54PM -0800, Drew Fustini wrote: > > > > + ret = strncpy_from_user(buf, user_buf, PINMUX_MAX_NAME * 2); > > > > + if (ret < 0) { > > > > + dev_err(pctldev->dev, "failed to copy buffer from userspace"); > > > > + goto free_gname; > > > > + } > > > > + buf[len-1] = '\0'; > > > > + > > > > + ret = sscanf(buf, "%s %s", fname, gname); > > > > + if (ret != 2) { > > > > + dev_err(pctldev->dev, "expected format: "); > > > > + goto free_gname; > > > > > > We need a "ret = -EINVAL;" before the goto. sscanf doesn't return error > > > codes. Normally we would write it like so: > > > > > > if (sscanf(buf, "%s %s", fname, gname) != 2) { > > > dev_err(pctldev->dev, "expected format: "); > > > ret = -EINVAL; > > > goto free_gname; > > > } > > > > > > I'm going to write a Smatch check for this today. > > > > It's a pretty frequently used style: > > > > $ git grep -P '\w+\s*=\s+sscanf\b' | wc -l > > 327 > > Yeah. That's true. I looked through a couple of those and they were > fine. (Sample size 2) But the other format is more common. > > $ git grep sscanf | grep = | wc -l > 803 > > I have written a Smatch check to complain whenever we propogate the > return value from sscanf. I'll let you know tomorrow how that goes. > > I should write another check which says "On this error path, we know > sscanf was not equal to the value we wanted but we are still returning > success". > > regards, > dan carpenter > Thank you for comments regarding sscanf(). And also thank you for the LF mentorship session on smatch this morning. It helped me understand it much better. Based on further comments, it seems there are better ways for me to pull the strings out of the write buffer, but I will keep this in mind if I need to use sscanf() in the future. -Drew