Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp529629imm; Fri, 29 Jun 2018 01:58:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+XB+TVAFFGpP6zDq+XkaRddoBKYE4JXHQfjQxAK7Es/DeMvTcbd5O5dG3VgZ/723oMvoK X-Received: by 2002:a62:820a:: with SMTP id w10-v6mr13321759pfd.71.1530262680414; Fri, 29 Jun 2018 01:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530262680; cv=none; d=google.com; s=arc-20160816; b=EnqF4NnikbqeoiXVrzY8uY70GLWV4JHoDGkw4l31Z9GPRyojHnltaxrNh2reaGOdgl I1u2qKuqNNq0bEibeKJ0SbnfHEIWf3uvpGBQFaDAjikk2xPymG7MftDHN22UEqmVA7f9 wRIBJMSCjeXVh7obV22X292/HXcKmdg7uiJQsSHaILXCjc68PHMyfdyeC8U5pLCvuety CWVhu8SQFlpbjVvPmKxRjfYcwqIJunZEbLuALdRHdU6vjadacsKhbpvJhSBw1Sm20tGV PxI+Bd6AOlChvTLtI8Pz/I4T8tp6uG/KR4Mgv6jIdrzWNxRGwZ0JzuorRQIoZDwH4bjA IMjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=9enrT/DRCRPXOC2q8MRtGanpjY8tHZre62iZ3RKB88k=; b=ZwCeHdp7YVqVaCpNyr30AGuPX+UdaGjq9Nxr1wFxtgRguaMh14L0ogb4uTbpEj2QE1 EqjlVtAT9h6KQuL4xyT4AQt30REW82UG/d4UU8GjuI4UE1Ub0ev52c3osibejETuQObr q/ujoUYMT07HD6H6zVOkITe+fASxERF2K4uCNop91wyiMClgwi4t7I13VuXrvfBQPV29 hsvr0nTI+rue5PtIbxgkRaBsPE/O7xtXWb7F5b2D960KdW8lnVWlwFtkMMa6zDh43Jdp ZZd7KGLXigOy0Z3AS8p4KKp4bjH8Kuzc1hgPTUCFEZ65B3z/CPiBdcYqxsEf5crpDwYP cQIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eZb4UkoH; 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 l7-v6si2585578pgs.541.2018.06.29.01.57.46; Fri, 29 Jun 2018 01:58:00 -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=eZb4UkoH; 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 S932913AbeF2FfX (ORCPT + 99 others); Fri, 29 Jun 2018 01:35:23 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:33880 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751981AbeF2FfV (ORCPT ); Fri, 29 Jun 2018 01:35:21 -0400 Received: by mail-pl0-f65.google.com with SMTP id z9-v6so3908127plo.1; Thu, 28 Jun 2018 22:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9enrT/DRCRPXOC2q8MRtGanpjY8tHZre62iZ3RKB88k=; b=eZb4UkoHEBCnaArDtBCDe5GH9PT3dKOVrqk1Gzo61Czqu9gwAmzOsrMIQIVOhc3KXV 9+7OaKL0zfkX8692L08/vjvEobew6MPROJWQK5CHsNycabJ6EmYk3yMlccqIlhiiJ/DT MZdsrtUWOhWUy6TAKOfmGTqn3LykK/qRtv9oBMgEhcwlM/B61MPPRqyJuIxl0OU3JCIA DiChnC1jM8YuTGidmhC1zVRRu0/JkOoQ/hcBLxPbbE68AHGf+OTkVVQ7YGwbOG2+IfqD B3tnESWKCaRCIa+14srlGLbaRk7/OoEBqRTJHV5EFk9+7jkD+eVBHInGxu849FKS6Ivj BSvA== 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:user-agent; bh=9enrT/DRCRPXOC2q8MRtGanpjY8tHZre62iZ3RKB88k=; b=EYvoO2sG8cPpYbVOD039Dom5OnEGR5SB/zessfOdes7tPpHecRNpQhLF171xQlnod7 j4HT/8GLCRMImRMBBqsdFoURyjoCvDuRVzACNT51z/iON2CF5/wJMV3V56sLCB7glGPf Dz3zR0frFf5xudB43tTd6+ZMGAyJXoXXO99nye/Z0Kbyzvh4oPDxfCFtdaIk9T7m0RM+ S7EtNzhQmtVBvEBQ+0aoCc4OjT3tvvaJB943ATVvodBJWTgtZnb6/9x5AdkwuEjdyhmS 7g6hdoo6BKkn/jqCYQIBv4Y7/NTTyQGTFeoANAyFRHRBLFlLHRR3i2NSCg58tMol19WC VzHA== X-Gm-Message-State: APt69E36JVgVgILn09jATwy8DGtWYhKaXEE/28sSO5R2kbqqd2p5pKI+ C/bG6Gt+9qyXdVnwle+bh+eexgxw X-Received: by 2002:a17:902:d24:: with SMTP id 33-v6mr13633296plu.22.1530250520869; Thu, 28 Jun 2018 22:35:20 -0700 (PDT) Received: from himanshu-Vostro-3559 ([103.233.116.134]) by smtp.gmail.com with ESMTPSA id g2-v6sm16514176pgn.92.2018.06.28.22.35.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 22:35:20 -0700 (PDT) Date: Fri, 29 Jun 2018 11:05:09 +0530 From: Himanshu Jha To: Stefan Popa Cc: jic23@kernel.org, Michael.Hennerich@analog.com, lars@metafoo.de, knaack.h@gmx.de, pmeerw@pmeerw.net, mchehab@kernel.org, davem@davemloft.net, gregkh@linuxfoundation.org, akpm@linux-foundation.org, linus.walleij@linaro.org, rdunlap@infradead.org, lukas@wunner.de, Ismail.Kose@maximintegrated.com, vilhelm.gray@gmail.com, sean.nyekjaer@prevas.dk, pombredanne@nexb.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/2] iio: dac: Add AD5758 support Message-ID: <20180629053509.GA2647@himanshu-Vostro-3559> References: <1530188012-28253-1-git-send-email-stefan.popa@analog.com> <20180628214818.GA3577@himanshu-Vostro-3559> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180628214818.GA3577@himanshu-Vostro-3559> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 29, 2018 at 03:18:18AM +0530, Himanshu Jha wrote: > On Thu, Jun 28, 2018 at 03:13:32PM +0300, Stefan Popa wrote: > > The AD5758 is a single channel DAC with 16-bit precision which uses the > > SPI interface that operates at clock rates up to 50MHz. > > > > The output can be configured as voltage or current and is available on a > > single terminal. > > > > Datasheet: > > http://www.analog.com/media/en/technical-documentation/data-sheets/ad5758.pdf > > > > Signed-off-by: Stefan Popa > > --- > [..] > > +static const int ad5758_dc_dc_ilim[6] = { > > + 150000, 200000, 250000, 300000, 350000, 400000 > > +}; > [..] > > +int cmpfunc(const void *a, const void *b) > > +{ > > + return (*(int *)a - *(int *)b); > > +} > > Since Kbuild hit a Sparse error in this function, I would also like to > add that the above implementation of cmpfunc() is not safe. > > For eg: https://wandbox.org/permlink/MqGnA3nVg7eAN4I7 > > The following will be safer: > > static int cmpfunc(const void *a, const void *b) > { > int arg1 = *(const int*)a; > int arg2 = *(const int*)b; > return (arg1 > arg2) - (arg1 < arg2); > } > > [..] > > + index = (int *) bsearch(&tmp, ad5758_dc_dc_ilim, > > + ARRAY_SIZE(ad5758_dc_dc_ilim), > > + sizeof(int), cmpfunc); I somehow realized that my argument is useless since we would not have large integer subtraction, which could lead to signed integer overflow(UB) and hence cause problems(as evident in the eg link I posted). Sorry Stefan :( -- Himanshu Jha Undergraduate Student Department of Electronics & Communication Guru Tegh Bahadur Institute of Technology