From patchwork Tue Nov 17 15:24:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 7638141 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CAE399F2EC for ; Tue, 17 Nov 2015 15:27:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D87F9204D8 for ; Tue, 17 Nov 2015 15:27:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EC97D200E7 for ; Tue, 17 Nov 2015 15:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754107AbbKQP1K (ORCPT ); Tue, 17 Nov 2015 10:27:10 -0500 Received: from mail-pa0-f65.google.com ([209.85.220.65]:33779 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753840AbbKQPZU (ORCPT ); Tue, 17 Nov 2015 10:25:20 -0500 Received: by padfb7 with SMTP id fb7so1749224pad.0; Tue, 17 Nov 2015 07:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=PSPvoV6ypXXOrVbJRjxoPXiMzb2rGAxvcRQadxFhfHc=; b=dUl5lpQBpj66hzzhu4rtbwGbx4e12/3esBNQWE7xr9b+7zjwYn594YTMEOeek1v03e IOwO19ujRfjSUETO50FHB42jRmthz52MFsTHfSgyxOm6dPybd3eRlMT38eVwJYfn5jSn L7h7FprAA/UTBpHhemTgxPB86dp/nWWqStgcP6IC8rDXM3APhDWwsBUDsJQa1JYrwX7V EtbVBiluGR9J9Cwq28Q1CKo6eDSuIc5g02Nbv+3tT7OjjpxYDhUfDhPX54AFgoWiCejg Uj3hDqPNDWBdgPHAzVUCfRJZGyOTdpdFumrp2IYIi8d15xAhnPeMQyQsbPRsvup8wlkU Ju+w== X-Received: by 10.68.230.170 with SMTP id sz10mr64236323pbc.139.1447773920121; Tue, 17 Nov 2015 07:25:20 -0800 (PST) Received: from localhost.localdomain (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id d7sm43701843pas.31.2015.11.17.07.25.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 07:25:19 -0800 (PST) From: Joshua Clayton To: Mark Brown Cc: Jonathan Corbet , Adrian Remonda , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Joshua Clayton Subject: [PATCH 2/8] Documentation/spi/spidev_test.c: clean up input_tx Date: Tue, 17 Nov 2015 07:24:22 -0800 Message-Id: <7f2139b27013d77993c6bc2b0a6c94fab01add98.1447773299.git.stillcompiling@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Put input from string into its own function. Signed-off-by: Joshua Clayton --- Documentation/spi/spidev_test.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Documentation/spi/spidev_test.c b/Documentation/spi/spidev_test.c index dfe8f47..1ed9110 100644 --- a/Documentation/spi/spidev_test.c +++ b/Documentation/spi/spidev_test.c @@ -249,12 +249,20 @@ static void parse_opts(int argc, char *argv[]) } } +static void transfer_escaped_string(int fd, char *str) +{ + size_t size = strlen(str + 1); + uint8_t *tx = malloc(size); + + size = unescape((char *)tx, str, size); + transfer(fd, tx, size); + free(tx); +} + int main(int argc, char *argv[]) { int ret = 0; int fd; - uint8_t *tx; - int size; parse_opts(argc, argv); @@ -299,15 +307,10 @@ int main(int argc, char *argv[]) printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); - if (input_tx) { - size = strlen(input_tx+1); - tx = malloc(size); - size = unescape((char *)tx, input_tx, size); - transfer(fd, tx, size); - free(tx); - } else { + if (input_tx) + transfer_escaped_string(fd, input_tx); + else transfer(fd, default_tx, sizeof(default_tx)); - } close(fd);