Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4654595imm; Mon, 11 Jun 2018 16:43:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLiQrHxwUZal2m1mUAlt5zIGsGfsSuPCpvN6PMRY6H7pQ4vyaEFhL3uFlvUe/EyR+4ggpiB X-Received: by 2002:a17:902:aa95:: with SMTP id d21-v6mr1257133plr.73.1528760627643; Mon, 11 Jun 2018 16:43:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528760627; cv=none; d=google.com; s=arc-20160816; b=J2UZ/1KkTTewzxJ3hX3woTIkAxZxDm4o5DTQWpOFpL4vwPFEVMdATRxVyaZPs5HRz/ VU+gWtCR762APxD4xfxopPdBlNnZqK5yHPuLlPXue/38zPCwuMC5I5+YxMOVgwncLcNZ 55xPz9+HwSoQnKJ1fO5JmP8+PjjP1dyth3QTvGka82HLEhaPyT/Yh00R3AUiOo6Igxqt tQmX/1ns+QDMhh6HFBKz3jzpKt0i6GUWxDbVBkp/m/gNpUAC7FmY4YCQU8lkI3jfkNpA FsiK3HMHIJdneOMJF/FBnA6G9+KYT9XE9xQugL/SzUy7qUzHX0AX9dgjFD6FF93mfCSI JwTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Kowt6W4Lu3VmAcdRbMR+SF4Mfkoi8DfU048bBivC2BM=; b=QZo5Nx5RnF8XmscPaFxjv/rNMyexpbERqJietyn3agyN+mpAHWCEP/BOSVnjKNy5ar 4gGiXvrObcnRJWfljia7RMFA9K/6mmsgBdLUDtSc884FuvEq7JnvBYLsnfawKjbbkbNr MIRGG7bja+jPcEtMR7eDFVBvboAxuMCqXL7Q6nc6fwOXZjsoOWfZ12pBZ4+EOcouxZWI 0XQ3LrE7kuSzNRutZLzXdh1hzaLT4KtSCXVDBpJoPtxxcHa4MGR9/jbPnrh+tTdsywtf CFHo5h4oWPwgyePoBN+nVkuXEGM4WkXh8P9YXrIc7LzLaHEaipnp9PsKXQXuLyKTNMSf uIsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MDR+DHfb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7-v6si22170490pll.445.2018.06.11.16.43.02; Mon, 11 Jun 2018 16:43:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MDR+DHfb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933394AbeFKXiX (ORCPT + 99 others); Mon, 11 Jun 2018 19:38:23 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:41040 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932471AbeFKXiV (ORCPT ); Mon, 11 Jun 2018 19:38:21 -0400 Received: by mail-wr0-f196.google.com with SMTP id h10-v6so22100389wrq.8; Mon, 11 Jun 2018 16:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Kowt6W4Lu3VmAcdRbMR+SF4Mfkoi8DfU048bBivC2BM=; b=MDR+DHfbC87d0nmXSHD1VFszD0plx83Nk/aGCOgaP0ePeuYyovKdX6hlWGGXYZAMuy vWVodmVhDcICKzR2tI6lfoqk6hEBCz5/1114wx/i8axDzVSQW1zTDc5ZmKFi2dEIvvSM v5nMI2VEtk6TzvD9BSFS3GtPWZFegaWZQRvLZTaPN9m4OSu5djMKYeeQOPsfL0J0NleG nMlSARbLk1ERBixYDzUKyvOx3o8xd88ah6tE7J6XbeYcOVhBs400FdhY6RaRbMPcQRhx alS/la6DTX39pYXUd7PkEY3X7AAvIhJZJbvMo6WkwxGpD0+rRgJqqhKEcdzH5mlXQZl8 Y+DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Kowt6W4Lu3VmAcdRbMR+SF4Mfkoi8DfU048bBivC2BM=; b=NFHJmfI91wiVS3betATiPKHl7ncALuQ11ykJC5jmlCmmr5T1+qu8ymA5p4fPDtlw6b FqqdEKcYWEKINjBHKbIOHs0enIgUzpO0/n/N2WzpAqLz1MuJaaleUQN3KAfLkyLvBAWF Jtc1ew8fUxG0rz8GNHKa3fd+keAKHq1DuCs2hZwfjKBfoc9FD8Z+zazUh3094hIFuAJn t1Xk61MWqEchcpQjIlw1lfmC8qGHTA5STtKcISPNbaHze3JHYQHBPkoKP31mE4eEr9LL U1RM93/k42T0HvIWEL3YFH0pWfbp/kY5DH7PyCizHoS4zwKuI2PugLBynba7jY0fc7em Mt1w== X-Gm-Message-State: APt69E3DWk3uctLFcNVxtuyM9UelPDJwI2q71ldmDraXD/yLVWmQKzAl 1erF0TBzeoZyNZYvUWESw8k= X-Received: by 2002:a5d:4503:: with SMTP id s3-v6mr784361wrq.191.1528760300507; Mon, 11 Jun 2018 16:38:20 -0700 (PDT) Received: from localhost.localdomain ([156.219.155.97]) by smtp.gmail.com with ESMTPSA id s17-v6sm6644718wmc.34.2018.06.11.16.38.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jun 2018 16:38:19 -0700 (PDT) From: Karim Eshapa To: lars@metafoo.de Cc: Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Karim Eshapa Subject: [PATCH] staging:iio:accel:adis16240: sign extend function avoiding code duplication Date: Tue, 12 Jun 2018 01:38:14 +0200 Message-Id: <20180611233814.18597-1-karim.eshapa@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use sign_extend32 kernel function instead of code duplication. Safe also for 16 bit. Signed-off-by: Karim Eshapa --- drivers/staging/iio/accel/adis16240.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/accel/adis16240.c b/drivers/staging/iio/accel/adis16240.c index fff6d99089cc..9adb5badb915 100644 --- a/drivers/staging/iio/accel/adis16240.c +++ b/drivers/staging/iio/accel/adis16240.c @@ -292,9 +292,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, ret = adis_read_reg_16(st, addr, &val16); if (ret) return ret; - val16 &= (1 << bits) - 1; - val16 = (s16)(val16 << (16 - bits)) >> (16 - bits); - *val = val16; + *val = sign_extend32(val16, bits - 1); return IIO_VAL_INT; case IIO_CHAN_INFO_PEAK: bits = 10; @@ -302,9 +300,7 @@ static int adis16240_read_raw(struct iio_dev *indio_dev, ret = adis_read_reg_16(st, addr, &val16); if (ret) return ret; - val16 &= (1 << bits) - 1; - val16 = (s16)(val16 << (16 - bits)) >> (16 - bits); - *val = val16; + *val = sign_extend32(val16, bits - 1); return IIO_VAL_INT; } return -EINVAL; -- 2.17.1