Linear codes with few weights have applications in data storage systems, secret sharing schemes and authentication codes. In this paper, inspired by the works of Heng and Yue (2016) [14] and Tan, Zhou, Tang and Helleseth (2017) [25], we extend Tan, Zhou, Tang and Helleseth's work to obtain a class of optimal 1-weight binary linear codes, new classes of 2-weight and 3-weight p-ary linear codes and a class of 4-weight binary linear codes. The lengths and weight distributions of the t-weight linear codes, where t=1,2,3, are closed-form expressions of Kloosterman sums over finite prime fields, and are completely determined when p=2 and p=3.