From patchwork Fri Sep 11 20:08:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 53502 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by patches.linaro.org (Postfix) with ESMTPS id E4A4922B26 for ; Fri, 11 Sep 2015 20:12:19 +0000 (UTC) Received: by lbcao8 with SMTP id ao8sf28086246lbc.1 for ; Fri, 11 Sep 2015 13:12:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=NmBY0Ge8gE/QuM79Hkpi5VwvUD7U5544KJul6hqySBc=; b=UumUv2SsM4TOia6Ub7Z5J5uIuftjBzReTCzNipxi91IONwF91wl86j9tunM7jkN96h XH3Z/B2zban7VrtOs/BeSfpNeiXrXn5ThV2XRtPKHTutoL213wjzNHLAS3lOWjb3YwRw /1SsHLDc34qqfu2vNbP7mZKO9XdxvQ0EROP84hTKX9UR0W36iPED3efh/dcXK5Xxx2kA 6D1HGQM7M3QHO05l+Wcpd24ALsNTLEYhPtmV3M8jceV4KMvBGOhmV4v3Mt9HqJsHYfXC 0pKZH8efYDyDgR6VTB/E5jiEKe6c6SlhWtmT3H9sScwTNxcOJ+E3AExOcgd4qflIlkQ9 P4bg== X-Gm-Message-State: ALoCoQmdrL5hwatbk1SIGUzaL+/eopWO4KCaPSM6+HoF0hUV/iIrh1+opoU5TZWfpZaMtSSp3w9h X-Received: by 10.152.120.233 with SMTP id lf9mr181365lab.2.1442002338912; Fri, 11 Sep 2015 13:12:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.136 with SMTP id w8ls364347lal.16.gmail; Fri, 11 Sep 2015 13:12:18 -0700 (PDT) X-Received: by 10.112.72.37 with SMTP id a5mr598307lbv.18.1442002338561; Fri, 11 Sep 2015 13:12:18 -0700 (PDT) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id m8si1219636lbs.149.2015.09.11.13.12.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Sep 2015 13:12:18 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbbmp1 with SMTP id mp1so45333017lbb.1 for ; Fri, 11 Sep 2015 13:12:18 -0700 (PDT) X-Received: by 10.112.156.167 with SMTP id wf7mr577886lbb.88.1442002338453; Fri, 11 Sep 2015 13:12:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1814015lbq; Fri, 11 Sep 2015 13:12:17 -0700 (PDT) X-Received: by 10.50.21.10 with SMTP id r10mr57949ige.94.1442002335852; Fri, 11 Sep 2015 13:12:15 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a11si501018igm.77.2015.09.11.13.12.15; Fri, 11 Sep 2015 13:12:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753833AbbIKUMM (ORCPT + 7 others); Fri, 11 Sep 2015 16:12:12 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:37349 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753949AbbIKUKi (ORCPT ); Fri, 11 Sep 2015 16:10:38 -0400 Received: by wicfx3 with SMTP id fx3so70092140wic.0 for ; Fri, 11 Sep 2015 13:10:37 -0700 (PDT) X-Received: by 10.194.85.163 with SMTP id i3mr972067wjz.75.1442002236914; Fri, 11 Sep 2015 13:10:36 -0700 (PDT) Received: from localhost.localdomain (host81-129-169-75.range81-129.btcentralplus.com. [81.129.169.75]) by smtp.gmail.com with ESMTPSA id fn8sm774193wib.2.2015.09.11.13.10.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Sep 2015 13:10:36 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, mpm@selenic.com, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, devicetree@vger.kernel.org, Lee Jones Subject: [PATCH 2/6] hwrng: core: Simplify RNG switching from sysfs Date: Fri, 11 Sep 2015 21:08:26 +0100 Message-Id: <1442002110-28733-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442002110-28733-1-git-send-email-lee.jones@linaro.org> References: <1442002110-28733-1-git-send-email-lee.jones@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If we attempt to use sysfs to change the current RNG in the usual way i.e. issuing something like: `echo 8a8a000.rng > /sys/devices/virtual/misc/hw_random/rng_current` ... it will fail because the code doesn't currently take the '\n' into consideration. Well, now it does. Signed-off-by: Lee Jones --- drivers/char/hw_random/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index da8faf7..14dc984 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -316,6 +316,7 @@ static ssize_t hwrng_attr_current_store(struct device *dev, const char *buf, size_t len) { int err; + int snip = 0; struct hwrng *rng; err = mutex_lock_interruptible(&rng_mutex); @@ -323,7 +324,11 @@ static ssize_t hwrng_attr_current_store(struct device *dev, return -ERESTARTSYS; err = -ENODEV; list_for_each_entry(rng, &rng_list, list) { - if (strcmp(rng->name, buf) == 0) { + + if (buf[len-1] == '\n') + snip = 1; /* Snip one character */ + + if (strncmp(rng->name, buf, len - snip) == 0) { err = 0; if (rng != current_rng) err = set_current_rng(rng);